Question

I have quite a large View Controller in my app and I want to clean it up by separating some of the functions into categories. I read up on how to implement a category and have:

#import "StatsVC.h"

@interface StatsVC (TableViewDelegate)

@end

As my .h (the category is called StatsVC+TableViewDelegate). and my Implemation starts like this:

@implementation StatsVC (TableViewDelegate)

Several times in the category, I access variables which are iVars of the original class.I have read and supposedly this is allowed, but for every use of an iVar in the category I get this error message:

'Use of undeclared identifier 'iVar'

Does anybody know why this is happening?

Thanks,

Was it helpful?

Solution

You definitely can access instance variables from methods in a category. Categories add methods to the class -- there's no real difference at run time between a method declared in the class interface and one declared in a category on that class. You'll probably need to show more code to get a good answer. Right now, my top two guesses are:

  1. You're trying to access ivars from a class method rather than an instance method, i.e. one starting with a + instead of a -.

  2. There's something wrong with the way you've declared the ivars.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top