Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// assumes object class called SENQuestionnaire
- (void)writeDictionaryToDisk:(SENQuestionnaire *)q
{
NSDictionary *dataDictionary =
@{
@"stringA" : @"string A",
@"stringB" : @"string B",
@"stringC" : @"string C",
};
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *doc = [basePath stringByAppendingString:@"/"];
NSString *file = [doc stringByAppendingString:q.uniqueID];
NSString *filePath = [file stringByAppendingString:@".plist"];
// plistDict is a NSDictionary
NSString *error;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dataDictionary
format:NSPropertyListXMLFormat_v1_0
errorDescription:&error];
if(plistData) {
[plistData writeToFile:filePath atomically:YES];
} else {
NSLog(@"%@",error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.