简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM