initWithCoder not working as expected?

Posted by fuzzygoat on Stack Overflow See other posts from Stack Overflow or by fuzzygoat
Published on 2010-03-15T17:04:44Z Indexed on 2010/03/15 17:09 UTC
Read the original article Hit count: 186

Filed under:
|

Does this seem right, the dataFilePath is on disk and contains the right data, but the MSMutable array does not contain any objects after the initWithCoder? I am probably just missing something, but I wanted to quickly check here before moving on.

-(id)initWithCoder:(NSCoder *)decoder {
    self = [super init];
    if(self) {
        [self setReactorCore:[decoder decodeObjectForKey:@"CORE"]];
    }
    return self;
}

.

-(id)init {
    self = [super init];
    if(self) {
        if([[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]) {
            NSMutableData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
            NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
            NSMutableArray *newCore = [[NSMutableArray alloc] initWithCoder:unArchiver];
            [self setReactorCore:newCore];
            [newCore release];
            [data release];
            [unArchiver release];
        } else {
            NSMutableArray *newCore = [[NSMutableArray alloc] init];
            [self setReactorCore:newCore];
            [newCore release];
        }
    }
    return self;
}

gary

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa-touch