我试图从应用程序保存一些设置为plist文件,当它关闭时,然后在应用程序启动时加载它们。我有4个数字保存在一个叫做数组的NSArray中。加载工作正常,因为如果我更改文件,应用程序将启动文件更改的方式。NSArray writeToFile返回“已弃用” - iPhone SDK
此代码工作正常:
- (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];
}
此代码到节约线路:
- (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
}
有谁知道我可以把它存到的plist?
〜感谢
感谢它的工作。我只有4个值来存储。 – 2010-07-15 18:34:24