I’m trying to figure out the best way to save my data.
Does it matter when you save data to the plist like so
NSString *error;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"yourFile.plist"];
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:rootObj
format:NSPropertyListXMLFormat_v1_0
errorDescription:&error];
if(plistData) {
[plistData writeToFile:plistPath atomically:YES];
}
else {
NSLog(@"Error : %@",error);
[error release];
}
or by using the NSData
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:FILE_NAME];
[myArray writeToFile:filePath atomically:YES];
I’m dealing with small XML files (which I parse into NSDictionaries) and large MP4 video. Are there any recommendations on which of these two file storage methods I should use? Thanks
I would go for
[myArray writeToFile:filePath atomically:YES];(fast, easy, less code)But only when your
NSArrayorNSDictionariesonly contains non-self objects (only containsNSNumber,NSString,NSArray, etc.).If you use
NSPropertyListSerializationyou should probably use the optionNSPropertyListBinaryFormat_v1_0. It’s faster and has smaller file size.But you also need to think if it makes sense to parse a XML to then store into a XML Plist. 🙂
Yes. It can make sense because then you can handle them more easy.
You can also consider to parse your XML and store it in a CoreData database. It then makes querying more easy.
The MP4 videos i would store also in the NSDocumentDirectory.