I'm attempting to initialize an array and add a chapter object to an array of book objects, but it crashes with the error:
2012-07-25 21:41:01.503 Project1[2364:f803] -[__NSCFString arrayOfChapters]: unrecognized selector sent to instance 0x6ad80b0 2012-07-25 21:41:01.505 Project1[2364:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString arrayOfChapters]: unrecognized selector sent to instance 0x6ad80b0'
My code:
Chapter *myChapter = [[Chapter alloc]init];
myChapter.pageCount = self.TextField2.text;
myChapter.chapterTitle = self.TextField1.text;
if(!currentBook.arrayOfChapters)
{
currentBook.arrayOfChapters = [[NSMutableArray alloc]init];
}
currentBook = [books objectAtIndex:segControl.selectedSegmentIndex];
[currentBook.arrayOfChapters addObject:myChapter];
I think the code is correct, is there something set up wrong with my project? I believe it's the initialization which is causing the actual crash, but there isn't anything non-standard there.
arrayOfChapters
? – pasawayacurrentBook
anywhere before the linecurrentBook = [books objectAtIndex:segControl.selectedSegmentIndex];
? – Ethan HolshouserarrayOfChapters
) of an item that's not, itself, initialized. You want to checkcurrentBook
before you start using it. – Rob