J'ai créé une liste de propriétés sous le nom propertys.plist. Ensuite, je l'ai écrit ceci:Impossible de lire et d'enregistrer un numéro à partir de/dans un .plist
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];
Quand je lance ce code à nouveau, je reçois toujours le numéro 0 dans le premier NSLog et le numéro 1 dans le second. Pourquoi?
Ce code est pour l'iPhone.
Ok, maintenant cela fonctionne, mais le code n'a pas enregistré la nouvelle valeur. Pourquoi? – Flocked
@Flocked: Est-ce le code pour iPhone ou Mac? – kennytm
Le code est pour l'iPhone - Donc iPhone OS – Flocked