0

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?

Sam Hosseini
  • 813
  • 2
  • 9
  • 17
SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
  • Part of your problem could be that `objectAtIndex` returns `id` and the parser does not recognise `tranCode` ? – cream-corn Oct 22 '14 at 23:48
  • No, because before I split this class (original was too large to manage) all of the code worked without any problems. – SpokaneDude Oct 22 '14 at 23:59

1 Answers1

1

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.

Community
  • 1
  • 1
jscs
  • 63,694
  • 13
  • 151
  • 195
  • Hi Josh... that took care of the problem; how would I call the class that is now in the category class? I have another class that instantiated the original class and called that method; it, of course, is not found anymore... i.e. UploadViewController *uvc = [[UploadViewController alloc]init]; [uvc createTabExportFile: @"Backup"]; – SpokaneDude Oct 23 '14 at 00:08
  • The category header needs to be imported wherever you want to call the methods that are defined in the category, which includes properties. – jscs Oct 23 '14 at 00:10
  • Ahhh Crap! I knew that... just forgot it... thanks again for your help; I appreciate it... have a good evening. SD – SpokaneDude Oct 23 '14 at 00:10
  • Sorry Josh... still not working... same exact problem even after I did what you suggested... except now it's "undeclared identifiers" in the category class for the same two objects... I've tried everything I could think of to no avail... – SpokaneDude Oct 23 '14 at 00:45