Category Ignorant Ivar

I have a pretty big view controller in my application and I want to clear it by dividing some functions into categories. I read about how to implement a category and has:

#import "StatsVC.h" @interface StatsVC (TableViewDelegate) @end 

Like my .h (the category is called StatsVC + TableViewDelegate). and my Implemation begins as follows:

 @implementation StatsVC (TableViewDelegate) 

Several times in a category, I refer to variables that are iVars of the source class. I have read and it is supposedly allowed, but for every use of iVar in the category I get this error message:

'Use of undeclared identifier 'iVar'

Does anyone know why this is happening?

Thanks,

+4
source share
1 answer

You can definitely access instance variables from methods in a category. Categories add methods to a class - there is no real difference at runtime between a method declared in the class interface and one declared in the category of this class. You will probably need to show more code to get a good answer. Right now, my first two guesses are:

  • You are trying to access ivars from a class method, not an instance method, i.e. starting with + instead of - .

  • There is something wrong with how you declared ivars.

+5
source

Source: https://habr.com/ru/post/1393573/


All Articles