ios - How do I fix this EXC_BAD_ACCESS in NSPropertyListSerialization? -


i using nspropertylistserialization sync nsdictionary via dropbox sync api. writing file works fine , shows in dropbox, trying read crashes exc_bad_access.

here's how i'm writing dropbox:

//create dictionary, add necessary stuff this. nsdata *data = [nspropertylistserialization datawithpropertylist:syncplistdictionary                                                               format:nspropertylistxmlformat_v1_0                                                              options:0                                                                error:null];     dberror *error = nil;     [syncfile writedata:data error:&error];     if (error) {         nslog(@"dropbox error writing file: %@", error);     }     [syncfile close]; 

this works fine , never logs error.

however, when try read later, crashes. here's how i'm reading file: (the data parameter comes dropbox file. dropbox sdk not give error when getting either.)

+ (nsdictionary *)dictionarywithcontentsofdata:(nsdata *)data {     nsdata *mydata = [data copy];     if ([mydata length]==0) {         return [[[nsdictionary alloc] init] autorelease];     }     if (!mydata) {         return nil;     }     // uses toll-free bridging data cfdataref , cfpropertylist nsdictionary     nserror *error = nil;     nsdictionary *dictionary = [nspropertylistserialization propertylistwithdata:mydata                                                                          options:0                                                                           format:nspropertylistxmlformat_v1_0                                                                            error:&error];     if (error) {         nslog(@"nsdictionary helper error: %@", error); //this never gets logged because crashes before getting here.     }     //[mydata release]; //i commented out thinking releasing fast made no difference.     return dictionary; } 

i got it:

+ (nsdictionary *)dictionarywithcontentsofdata:(nsdata *)data {     nsdata *mydata = [data copy];     if ([mydata length]==0) {         return [[[nsdictionary alloc] init] autorelease];     }     if (!mydata) {         return nil;     }     // uses toll-free bridging data cfdataref , cfpropertylist nsdictionary     nserror *error = nil;     nspropertylistformat plistformat;     nsdictionary *dictionary = [nspropertylistserialization propertylistwithdata:mydata                                                                          options:0                                                                           format:&plistformat                                                                            error:&error];     if (error) {         nslog(@"nsdictionary helper error: %@", error);     }     [mydata release];     return dictionary; } 

all had was: nspropertylistformat plistformat; , format:&plistformat instead of format:nspropertylistxmlformat_v1_0


Comments

Popular posts from this blog

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -