J'essaie d'enregistrer certains paramètres de mon application dans un fichier plist lorsqu'il se ferme, puis de les charger lorsque l'application est lancée. J'ai 4 numéros enregistrés dans un tableau appelé NSArray. Le chargement fonctionne bien car si je change le fichier, l'application démarre la façon dont le fichier a été modifié.NSArray writeToFile renvoyant "is deprecated" - iPhone SDK
Ce code fonctionne très bien:
- (void)LoadSettings {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:kSaveFileLocation];
NSArray *array = [[NSArray alloc] initWithContentsOfFile:finalPath];
clockFaceImageSlider.value = [[array objectAtIndex:0] integerValue];
HourTypeSwitch.on = [[array objectAtIndex:1] integerValue];
touchRotationSwitch.on = [[array objectAtIndex:2] integerValue];
accelerometerRotationSwitch.on = [[array objectAtIndex:3] integerValue];
}
Ce code fonctionne jusqu'à la ligne sauver:
- (void)SaveSettings {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:kSaveFileLocation];
NSArray *array = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:clockFaceImageSlider.value], [NSNumber numberWithInt:HourTypeSwitch.on], [NSNumber numberWithInt:touchRotationSwitch.on], [NSNumber numberWithInt:accelerometerRotationSwitch.on], nil];
if (![array writeToFile:finalPath atomically:YES]) {
NSLog(@"error");
}
//The log does print error
}
Est-ce que quelqu'un sait comment je peux le faire enregistrer au plist?
~ merci
Merci cela a fonctionné. Je n'ai que 4 valeurs à stocker. –