1

I know there is a lot of resources about that here but yet, I can't find what's going wrong with my code:

I have a class Level and two subclasses of Level: GameLevel and TransitionLevel. Each of this class implements the NSCoding protocol. Then, I've got an array of Level (so it contains both classes of GameLevel and TransitionLevel). Saving the archive seems to work fine :

NSString *archivePath = [DOCUMENT_DIRECTORY stringByAppendingPathComponent:@"levels.archive"];
[NSKeyedArchiver archiveRootObject:levels toFile:archivePath];

Note that levels is the array I want to save. I can see the file, it's created and seems to contains what it's supposed to contain. But when I want to retrieve this array :

NSString *archivePath = [DOCUMENT_DIRECTORY stringByAppendingPathComponent:@"levels.archive"];
levels = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];

I've got this exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

I'm not sure what I'm missing here.

Caleb
  • 124,013
  • 19
  • 183
  • 272
rmonjo
  • 2,675
  • 5
  • 30
  • 37
  • I'm not sure why my salutations are always removed when I post. So hello :) – rmonjo Mar 20 '12 at 18:00
  • No need to add superfluous stuff like "Hello," "Thanks," "Regards," etc. to your question. The SO software will remove some of that automatically; other times, people will edit your question to remove it. Save everyone time by leaving it out in the first place -- it's not rude, and it'll make for a question that better stands the test of time. If you want to add a personal touch, consider filling out your [profile](http://stackoverflow.com/users/251552/user251552) instead. – Caleb Mar 20 '12 at 18:32

1 Answers1

1

Either your implementation of initWithCoder: returns nil, either some part of your code tries to insert a nil value into an array.

You may go in the Breakpoint Navigator (⌘6) and add an Exception Breakpoint. Then, when the application raises an exception, the Debug Navigator will display the stack of the functions and methods currently executed. This would allow you to know precisely which method is trying to insert nil into an array.

Nicolas Bachschmidt
  • 6,475
  • 2
  • 26
  • 36
  • Thank you very much I have never used this view before, and it's pretty handy. I found my mistake directly (it was a stupid one). – rmonjo Mar 20 '12 at 18:22