Q:

unrecognized selector sent to instance

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.

A:

you can make a breakpoint on the line "if(!currentBook.arrayOfChapters)" to check whether the currentBook is nil;
make a breakpoint on the line"currentBook = [books objectAtIndex:segControl.selectedSegmentIndex];
" to check whether the segControl.selectedSegmentIndex >= [books count]

