Iphone 是否将字符串保存到属性列表(plist)文件?
我一直在尝试保存到属性列表文件,但是它不起作用,因为它只是将对象保存到数组中,而不是实际的文件本身,这意味着它保存的内容显然不会持久化Iphone 是否将字符串保存到属性列表(plist)文件?,iphone,arrays,plist,Iphone,Arrays,Plist,我一直在尝试保存到属性列表文件,但是它不起作用,因为它只是将对象保存到数组中,而不是实际的文件本身,这意味着它保存的内容显然不会持久化 [[category objectAtIndex:questionCounter] replaceObjectAtIndex:5 withObject:myString]; [category writeToFile:filePath atomically:YES]; 我在前面使用它将属性列表文件保存到文档目录,以便编辑并保存到它们: NSArray *pat
[[category objectAtIndex:questionCounter] replaceObjectAtIndex:5 withObject:myString];
[category writeToFile:filePath atomically:YES];
我在前面使用它将属性列表文件保存到文档目录,以便编辑并保存到它们:
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistFilePath = [documentsDirectory stringByAppendingPathComponent:fileNameFull];
if([[NSFileManager defaultManager] fileExistsAtPath:plistFilePath]) {
category = [NSMutableArray arrayWithContentsOfFile:plistFilePath];
NSLog(@"Files exist.");
}
else {
filePath = [[NSBundle mainBundle] pathForResource:fileNamer ofType:@"plist"];
category = [NSMutableArray arrayWithContentsOfFile:filePath];
NSLog(@"Files have been created.");
}
我的属性列表由数组组成,在这些数组中,我试图保存我的对象(字符串)。我觉得这是一件小事,但我看不出来。当您试图保存阵列时,您正在传入
文件路径,该路径指向无法写入的主捆绑包目录。您希望改用plistFilePath
,如下所示:
[category writeToFile:plistFilePath atomically:YES];