The default archiver generates binary. If you want XML, you have to change the output format.
NSMutableData *archiveData = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:archiveData];
archiver.outputFormat = NSPropertyListXMLFormat_v1_0;
[archiver encodeRootObject:self.Books];
[archiver finishEncoding];
Now you can send your archiveData
to the server. If you want JSON instead, it's easier still, and does not require a third-party framework.
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.Books
options:0
error:&error];
There are many options for writing data to disk, including the NSData
methods
– writeToFile:atomically:
– writeToFile:options:error:
– writeToURL:atomically:
– writeToURL:options:error:
EDIT
In response to the question in the comments... you can easily write the data to a file...
[archiveData writeToFile:filePath atomically:YES];
or
[jsonData writeToFile:filePath atomically:YES];