I’ve finally managed to save my data using NSCoding and a plist file.
However, the solution (cobbled together from various tutorials) uses an Archiver so the resulting plist file is binary.
I’d like to save the data in a text/readable plist xml file (at least for testing purposes) since I can read it.
How can I change my code to do this?
My “encodeWithCoder” and “initWithCoder” methods are in my Class designation.
My AppDelegate uses this to save the data where “allMsgs” is an array of Class instances:
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:allMsgs];
[encodedObject writeToFile:plistPath atomically:YES];
The AppDelegate uses this to read the data:
NSData *codedData = [[NSData alloc] initWithContentsOfFile:plistPath];
if(codedData!=nil){
allMsgs = [NSKeyedUnarchiver unarchiveObjectWithData:codedData];
}
Here is an example on how you can save your data in a plist:
Since a plist is actually represented by a NSDictionary your data must be able to be stored in a dictionary.