Search code examples
iosparse-platformnskeyedunarchiver

NSKeyedUnarchiver unarchiveObjectWithData: in Parse block function never returns


I am requesting a file representation of an NSDictionary from Parse.com (yes I know there are other more obvious ways to store dictionaries) and then in the completion block the data gets unarchived and assigned to a property.

When this code executes it never seems to return from the unarchive line. Nothing freezes, there is no error or exception. The app continues running as though everything is fine. If I set break points at the unarchiver line and the line after it, the first breakpoint gets hit but the second never does.

I can confirm that the function has returned the expected amount of data for this file.

PFFile *definitionFile = appObject[@"myFile"];  //PFFile reference from a PFObject
[definitionFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if (!error) {
        if (data) {
            //A breakpoint on the following line does fire and show that there is data being given to the unarchiver
            self.pendingDefinition = (NSDictionary *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
        }
        //////Nothing beyond this point gets executed////////
        [self handleNewDefinition];
    } else {
        NSLog(@"ERROR");
    }
}];

Solution

  • As it turned out the data was being stored as a plist and I needed to use plist serialization to extract it:

    if (data) {
                NSError *error;
                NSPropertyListFormat format;
                NSDictionary* plist = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:&error];
                if(!plist){
                    NSLog(@"Error: %@",error);
                }