Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jlobe

macrumors newbie
Original poster
Feb 2, 2010
9
0
Cali
When i first open my program, im getting:

NSInvalidArgumentException : *** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)

After i have samed my data to the same location, etc etc. I'm able to use the same method & NSKeyedUnarchiver to reload the data.

Relevant code:

Code:
-(void)saveDictionary {    
    NSString* plistPath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
    
    NSMutableData *saveData = [[NSMutableData alloc] init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: saveData];
    //existingObjects is a dictionary of custom objects (NSCoding compliant) that i want to save
    [archiver encodeObject:existingObjects forKey:archiveKey ];
    [archiver finishEncoding];
    [archiver release];
    
    if([saveData writeToFile:plistPath atomically: YES]) {
        [self loadDictionary];   //here: writeToFile works fine; and even loadDictionary works fine!
    }
    [saveData release];
}

-(BOOL)loadDictionary {
    NSString* plistPath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
    
//Using try/catch/final just for debugging purposes
@try {
        NSMutableData *saveData = [[NSMutableData alloc] initWithContentsOfFile:plistPath];
       //This is where it errs; only on initial launch
        NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:saveData];
        existingObjects = (NSMutableDictionary *)[unarchiver decodeObjectForKey:archiveKey];
        [unarchiver finishDecoding];
    }
    @catch (NSException * except) {
           //initialize a default existingObjects dictionary .....
           // ....
    }
    @finally {
        [existingObjects retain];
    }    
    return YES;
}

Why would I only get this error when I first open the application? Could there be something corrupting the plist (e.g. my previous failed attempts to learn how to save data)?
Thanks for the help, if theres other info needed/that would be helpful let me know.

Cheers
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.