Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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 如何在xcode 4.3.2中创建plist文件_Iphone_Ios_Plist - Fatal编程技术网

Iphone 如何在xcode 4.3.2中创建plist文件

Iphone 如何在xcode 4.3.2中创建plist文件,iphone,ios,plist,Iphone,Ios,Plist,我正在尝试创建我自己的plist文件,以便在我的应用程序中使用,我使用苹果作为参考 但是,我已经了解到,如果您创建自己的plist,则需要将其放置在应用程序构建的资源文件夹中。问题是我的构建中没有资源文件夹。。。所以我受伤了我该怎么办?。。我读过这篇文章,Answer先生说把plist文件放在supportingfiles文件夹就可以了。。允许也读取和写入plist,这样做可以吗?您可以将plist文件放在任何您想要的地方。 重要的是将其复制到包中。所以为了确保那张支票 项目设置>构建阶段>复制

我正在尝试创建我自己的plist文件,以便在我的应用程序中使用,我使用苹果作为参考


但是,我已经了解到,如果您创建自己的plist,则需要将其放置在应用程序构建的资源文件夹中。问题是我的构建中没有资源文件夹。。。所以我受伤了我该怎么办?。。我读过这篇文章,Answer先生说把plist文件放在supportingfiles文件夹就可以了。。允许也读取和写入plist,这样做可以吗?

您可以将plist文件放在任何您想要的地方。 重要的是将其复制到包中。所以为了确保那张支票
项目设置>构建阶段>复制捆绑资源


您可以通过在项目导航器中左键单击您的项目来打开项目设置。

要读取和写入plist,最佳做法是将其复制到文档根目录,如果您希望通过您没有写入权限的捆绑包访问它。我在这里提供了代码的快照,以及如何实现这一点

NSError *err;
NSFileManager *fileManager = [NSFileManager defaultManager];
//getting the path to document directory for the file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [paths objectAtIndex:0];
NSString *path = [documentDir stringByAppendingPathComponent:@"YourFile.plist"];

//checking to see of the file already exist
if(![fileManager fileExistsAtPath:path])
{
    //if doesnt exist get the the file path from bindle
    NSString *correctPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"YourFile.plist"];
    //copy the file from bundle to document dir
    [fileManager copyItemAtPath:correctPath toPath:path error:&err];      
}

一旦应用程序捆绑包安装在设备上,您就无法写入它。一旦安装了应用程序,您需要将其复制到应用程序沙盒中,然后您就可以从那里进行读写了。就xcode项目而言,你可以把文件放在任何你想放的地方。谢谢你的快速回复。。好吧,我现在明白了。。我已经准备好了它需要在捆绑包中,但不是100%的关于它包含了什么或没有包含什么…好的,谢谢,我想我之前找到了一个与此非常相似的教程。我正在考虑拥有一个控制器类,它将为我完成所有plist的工作,所以当我需要为它编写一些东西时,我可以调用我需要的类方法。等你认为这是一个好主意吗?是的,这是一个很好的实践,它可以解决代码重复问题,如果你需要帮助,我可以向你展示我创建的一个类,它可以读写到plist?你相信我已经成功地按照教程进行了学习,并且一切都进行得很好。。然而,我现在正试图在plist的根字典中添加一个字典。。我不知道如何设置这些值等等。。我有一个问题要问,你也许能帮我解决P