Last active
August 29, 2015 14:01
-
-
Save shahdhiren/f0f4fe7e2c9b5aa2e8b7 to your computer and use it in GitHub Desktop.
Create Plist File Programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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