I created a property list with the name propertys.plist. Then I wrote this:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"speicherung.plist"];
NSMutableArray *plistData = [[NSMutableArray arrayWithContentsOfFile:finalPath] retain];
int a = [[plistData objectAtIndex:1] intValue];
NSLog(@"%i", a); // returns always 0 - Even If I set a other number in the plist
a = a + 1;
NSNumber *ff = [NSNumber numberWithInt:a];
[plistData insertObject:ff atIndex:1];
NSLog(@"%@", [plistData objectAtIndex:1]); // returns 1 - right, because 0 + 1 = 1
[plistData writeToFile:finalPath atomically:YES];
When I run this code again, I always get number 0 in the first NSLog and number 1 in the second. Why?
This code is for the iPhone.
This is an NSNumber. So the address of this ObjC object is converted to an integer and assigned to
a, giving the strange value. Use-intValueto extract an integer from it.