Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 是否将字符串保存到属性列表(plist)文件?_Iphone_Arrays_Plist - Fatal编程技术网

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];