I have found couple of similar topic about this but none of them solve my problem. basically I want to read nsstring from my array in plist and then I want to overwrite the nsstring value.
我找到了几个类似的主题,但没有一个能解决我的问题。基本上我想从plist中的数组中读取nsstring,然后我想覆盖nsstring值。
NSArray *directoriespaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDir = [directoriespaths objectAtIndex:0];
NSString *fullnamefordir = [documentsDir stringByAppendingPathComponent:@"data.plist"];
NSArray *turns = [NSArray arrayWithContentsOfFile:fullnamefordir];
NSString *resultofarray = [turns objectAtIndex:0];
NSLog(@"%@",turns);
NSLog(@"%@",resultofarray);
nslog always shows null and i'm not trying to save anything so far because i can't even read the value :/
nslog总是显示null,我到目前为止我没有尝试保存任何东西,因为我甚至无法读取值:/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>8</string>
</array>
</plist>
i also tried with nsdictionary but it also doesn't work thanks in advance :)
我也尝试过nsdictionary,但它也无法提前感谢:)
1 个解决方案
#1
3
First Check whether your plist file exist in Document Directory or not.
首先检查您的plist文件是否存在于文档目录中。
NSFileMangaer *objFileManager=[[NSFileManager alloc]init];
BOOL isfileExist=[objFileManager fileExistsAtPath:yourDocumentDirectoryPath];
IF Bool Value is true then check you content of plist. May be the file doesnt exist in document directory ,it is in resource. If you didnot copied you plist from resource folder to document directory then first copy it there and then try to access it.
如果Bool值为true,则检查plist的内容。可能是文件目录中不存在的文件,它在资源中。如果您没有将plist从资源文件夹复制到文档目录,则首先将其复制到那里,然后尝试访问它。
#1
3
First Check whether your plist file exist in Document Directory or not.
首先检查您的plist文件是否存在于文档目录中。
NSFileMangaer *objFileManager=[[NSFileManager alloc]init];
BOOL isfileExist=[objFileManager fileExistsAtPath:yourDocumentDirectoryPath];
IF Bool Value is true then check you content of plist. May be the file doesnt exist in document directory ,it is in resource. If you didnot copied you plist from resource folder to document directory then first copy it there and then try to access it.
如果Bool值为true,则检查plist的内容。可能是文件目录中不存在的文件,它在资源中。如果您没有将plist从资源文件夹复制到文档目录,则首先将其复制到那里,然后尝试访问它。