5

In plist,I want to keep an array in each dictionary (Item).And if it is created,how I can send elements to that array.For example,If I created an account for an user,I will keep name,sex,email,password everything in a dictionary(item),in the similar way an array which contains inbox messages.Then I want to know that how I can store coming messages to that inbox array.

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
Rajkumar
  • 179
  • 6
  • Yes I took array as Mutable but,facing difficult when I adding element to that array .It is that when we adding ,we should have to declare dictionary at entering details.similarly when we have to send a message,again we have to declare a dictionary and have to save it.Then it becoming ,in plist another dictionary is creating and messages are going to it.It not joining in already existed account. – Rajkumar Jun 20 '12 at 12:21

2 Answers2

0

NSArray *array=[NSArray arrayWithObjects:<#(id), ...#>, nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
NSString *location = [libraryDirectory stringByAppendingString:@"/somefilename.plist"];
[array writeToFile:location atomically:YES];

Array can be loaded as below:
path = [bundle pathForResource:@"file" ofType:@"plist"]; array = (path != nil ? [NSArray arrayWithContentsOfFile:location] : nil);

0

For personal use I built some classes for easy saving/reading from NSUserDefaults - but can be adapted fairly easy to read/write any plist file. Download the class here

tagyro
  • 1,638
  • 2
  • 21
  • 36