无法在文档文件夹中创建plist文件 [英] can't creating plist file in document folder

查看:52
本文介绍了无法在文档文件夹中创建plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Viewdidload 方法中编写了这样的代码.但是它不会创建文件 .plist .

I have write code like this in Viewdidload method. But it don't create file .plist.

我不知道代码是wi8还是错误.而我必须在哪里写?

I don't know whether code is wi8 or wrong. And where i have to write?

NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory =  [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data1.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];

if ( ![fileManager fileExistsAtPath:path] ) {
    NSString *pathToSettingsInBundle = [[NSBundle mainBundle] 
    pathForResource:@"data1" ofType:@"plist"];
}

推荐答案

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString *documentsDirectory = [paths objectAtIndex:0]; 

plistpath = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:@"Product.plist"]];

然后

[array writeToFile:path atomically:YES]; 

[Whatever [Array or Dictionary] you want to Write in Plist]

如果仍然没有创建plist,请检查您的数组或字典是否必须为空.

If it is still not creating the plist then check whether your array or dictionary must be empty.

这篇关于无法在文档文件夹中创建plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆