Reputation: 9390
I have ten arrays in my application. I want to write those array values into the (document s directory)plist. Is possible to put 10 arrays into the one plist?.Else i will create separate plist for each arrays. Which one is possible to implement my application?. Please guide me and give some sample links.
Thanks
Upvotes: 2
Views: 1701
Reputation: 14148
It's pretty easy to do all you want.
How to make a file path to your applications document directory:
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* plistpath = [[paths objectAtIndex:0] stringByAppendingPathComponent: @"myplist.plist"];
How to read it in:
NSDictionary *dictionary;
dictionary = [NSDictionary dictionaryWithContentsOfFile:plistpath];
NSArray* array1 = [dictonary objectForKey: @"array1"];
NSArray* array2 = [dictonary objectForKey: @"array2"];
... etc ...
How to write it out:
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:array1 forKey:@"array1"];
[dictionary setObject:array2 forKey:@"array2"];
... etc ...
[dictionary writeToFile:plistPath atomically:NO];
Upvotes: 4