views:

23

answers:

1

In my Row class I have the initWithCoder method and everything restored in that method works fine, but only within the method. After the method is called I loose an array of sounds that is in my Row class. The sounds class also has the initWithCoder method, and the sound plays fine but only in the Row class initWithCoder method. After decoding the Row object, the sound array disappears completely and is unable to be called.

Here's my source for the initWithCoder:

- (id) initWithCoder:(NSCoder *)coder {
    ...
    soundArray = [coder decodeObjectForKey:@"soundArray"];
    NSLog(@"%d",[soundArray count]);
    return self;
}

the log shows the count as 8 like it should (this is while unarchiving). Then the row object I create gets assigned. And the resulting row object no longer has a soundArray.

[NSKeyedArchiver archiveRootObject:row toFile:@"DefaultRow"];
...
row = [NSKeyedUnarchiver unarchiveObjectWithFile:@"DefaultRow"];

So now whenever I call the soundArray it crashes.

//ERROR IS HERE
NSLog(@"%d",[[row soundArray] count]);

Help please (soundArray is an NSMutableArray).

+2  A: 
wbyoung
You just solved all my problems. Thank you sir.
Dane Man
Dane Man: Don't skip the documentation wbyoung linked you to. Read it, and read it all. It is required reading for every Cocoa and Cocoa Touch programmer.
Peter Hosey