Search code examples
objective-ccompiler-warningsobjective-c-categorydeclared-property

Properties defined in category not found in original class


I have a very large class that I am trying to create a category from. In the original class' .m file, I have 2 objects (defined in the category .h file) that I'm getting "unidentified identifier" build errors.

This is the object definition of one of them in the UploadViewController+CreateExportFiles.h class:

@property (strong, nonatomic) NSArray *booksArray;

The .h file of the original class (UploadViewController.h) looks like this:

#import "UploadViewController.h"
#import "UploadViewController+CreateExportFiles.h"

and the usage of booksArray in the class where I'm getting the error is:

if( [[[booksArray objectAtIndex:i] tranCode] isEqualToString:@"A"]) 

Is there something else I have to do to resolve the error?


Solution

  • Categories can't add storage to classes. By moving the property declaration to a category from the main class interface, you've stopped the compiler from creating the ivar booksArray for you, which is the entity that you're referring to with [booksArray objectAtIndex:i].

    You need to put the property back into the main class interface or a class extension, or use a workaround.