Skip to content

Instantly share code, notes, and snippets.

@shahdhiren
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahdhiren/f0f4fe7e2c9b5aa2e8b7 to your computer and use it in GitHub Desktop.
Save shahdhiren/f0f4fe7e2c9b5aa2e8b7 to your computer and use it in GitHub Desktop.
Create Plist File Programmatically
NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:1];
NSString *stringFormat = @"My String stored in plist"; // Here any object can be pass NSNumber, NSArray, NSString, BOOL, NSDictionary.
[rootObj setObject:stringFormat forKey:@"commsEncodingFormat"];
NSString *error = nil;
id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
NSString *finalPath = [libraryDirectory stringByAppendingPathComponent:@"strings.plist"];
[[NSFileManager defaultManager] createFileAtPath:finalPath contents:plist attributes:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment