PDA

View Full Version : plist data read/write in xcode to iPhone, 2.Dictionary / 4.item to write syntactic ?




harryman
Mar 12, 2009, 11:41 AM
Hi
please help

this is to iPhone application data.plist structure :
- Root / Array
- '1' / Dictionary
- 'A' / item / string = "empty 1"
- 'B' / item / string = "empty 2"
- 'C' / item / string = "empty 3"
- 'D' / item / number = 23
- 'E' / item / number = 15

- '2' / Dictionary
- 'A' / item / string = "empty 1"
- 'B' / item / string = "empty 2"
- 'C' / item / string = "empty 3"
- 'D' / item / number = 4562
- 'E' / item / number = 8602

xcode detail:
...
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.pathToUserCopyOfPlist = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];

if ([fileManager fileExistsAtPath:pathToUserCopyOfPlist] == NO) {
NSString *pathToDefaultPlist = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
if ([fileManager copyItemAtPath:pathToDefaultPlist toPath:pathToUserCopyOfPlist error:&error] == NO) {
NSAssert1(0, @"Failed to copy data with error message '%@'.", [error localizedDescription]);
}
}
self.data = [[[NSMutableArray alloc] initWithContentsOfFile:pathToUserCopyOfPlist] autorelease];
...
// all data array write to display ('1' and '2' all item value)
NSLog(@"adat = %@",data);
// 2.Dictionary data array write to display
NSLog(@"adatsor = %@",[data objectAtIndex:1]);

i'm can to read :
NSLog(@"2. row 5.item = %@",[[data objectAtIndex:1] objectForKey:@"E"]);
summa : 8602

but no can write this is in sample plist '2' Dictionary / '4' item

thank you