在文件目录中找不到plist文件?如何以编程方式修改plist? [英] Can not find plist file in documents directory? How to modify the plist programatically?

查看:121
本文介绍了在文件目录中找不到plist文件?如何以编程方式修改plist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XCode 4.2中有一个应用程序。

I have an application in XCode 4.2.

我已根据我的要求创建了plist文件。

I have created plist file as my requirement.

我找到了Applications main bundle中的数据并将数据输入到数组中。

I have found the data from Applications main bundle and got the data in to the array.

但是我想在运行时修改plist数据,我找不到它在文档目录中

But As I want to modify the plist data at run time, I could not find it in Documents Directory

实际上我想以编程方式修改plist。尽管我没有使用mainbundle。

Actually I want to modify the plist programatically.Though I am not using mainbundle.

   -(NSString *) saveFilePath::(NSString *)tagString     
  {

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

NSString *strPath = [[arr objectAtIndex:0] stringByAppendingPathComponent:tagString];       
       return strPath;

       } 

无法检索plist文件。(路径我得到了,但文件没有到达的路径)

Could not retrive the plist file.(Path I am getting, but path with file not getting)

I also could not find physically the plist file in the iphone simulator/App/Documents folder?


推荐答案

您需要首先将plist从bundle复制到文档目录

you need to copy plist from bundle to document directory first

-(void) checkAndCreateSetting
{
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath= [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Settings.plist"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

如有任何疑问,请告诉我
谢谢&问候
neil

let me know in case of any query thanks& regards neil

这篇关于在文件目录中找不到plist文件?如何以编程方式修改plist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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