ios 在 Xcode 中创建和编辑 plist 文件的步骤

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9044735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:32:32  来源:igfitidea点击:

Steps to create and edit a plist file in Xcode

iosiphonexcodeplistkey-value

提问by Gopinath

I want to add key pair values in plist. I dont know how to add the .plist file in XCode. Simply i want to add these details in .plist file named as "Mobile.plist".

我想在plist. 我不知道如何在 XCode 中添加 .plist 文件。只是我想在名为“ Mobile.plist”的.plist 文件中添加这些详细信息。

Apple - iPhone,iPod,iPad
Samsung - Galaxy Y, Galaxy R, Galaxy Z
Nokia - Lumina
LG - Lg1 ,Lg2, Lg3

I have tried the steps to create a new Mobile.plist file by using this link,

我已尝试使用此链接创建新的 Mobile.plist 文件的步骤,

http://iphoneincubator.com/blog/tutorial/how-to-create-an-iphone-preferences-file. But, i cant get it exactly. When i tried to use the steps from this link, the plist file always empty. I don't know how to add the key, values in plist.

http://iphoneincubator.com/blog/tutorial/how-to-create-an-iphone-preferences-file。但是,我不能完全理解。当我尝试使用此链接中的步骤时,plist 文件始终为空。我不知道如何在 plist 中添加键值。

I have created one group named as Settings and add new plist file named as Root.plist. Can you please provide the steps to create .plist file and add key,values in it. Thanks in advance.

我创建了一个名为Settings and add new plist file named as Root.plist. 您能否提供创建 .plist 文件并在其中添加键值的步骤。提前致谢。

回答by Abizern

Right click on the folder you want to add it to and choose "New file…"

右键单击要添加到的文件夹,然后选择“新建文件...”

From the Dialog - create a new Resource file of type Property List:

从对话框 - 创建一个新的属性列表类型的资源文件:

enter image description here

在此处输入图片说明

Give it whatever name you want, the plist extension will be added for you. In this case I've created Root.plist

给它任何你想要的名字,plist 扩展将会为你添加。在这种情况下,我创建了 Root.plist

This will bring up a blank file with columns for Key, Type and Value.

这将打开一个包含键、类型和值列的空白文件。

enter image description here

在此处输入图片说明

Right click in the file and choose "Add Row"

右键单击文件并选择“添加行”

enter image description here

在此处输入图片说明

Choose any of the presented options, you'll be overwriting it anyway.

选择任何显示的选项,无论如何你都会覆盖它。

enter image description here

在此处输入图片说明

Now change the Key to "Apple". Right click in the type section, where it currently says String and change it to Array.

现在将密钥更改为“Apple”。右键单击类型部分,当前显示的是 String 并将其更改为 Array。

enter image description here

在此处输入图片说明

Click on the disclosure triangle next to where it says Apple so it faces downwards and then right click in the row and choose "Add Row" This will create a subrow under the Apple key. Repeat this until you have three rows:

单击 Apple 旁边的显示三角形,使其面朝下,然后右键单击该行并选择“添加行”这将在 Apple 键下创建一个子行。重复此操作,直到您有三行:

enter image description here

在此处输入图片说明

Edit the values to the three items that you want

将值编辑为您想要的三个项目

enter image description here

在此处输入图片说明

Click on the Disclosure triangle to the left of "Apple" on the top row so it points to the right. Right click on the row and choose "Add Row". This will create a new top level item.

单击顶行“Apple”左侧的“披露”三角形,使其指向右侧。右键单击该行并选择“添加行”。这将创建一个新的顶级项目。

enter image description here

在此处输入图片说明

Since you have four top level items, each which contains an array, repeat the above process so that you get the structure you want.

由于您有四个顶级项目,每个项目都包含一个数组,因此请重复上述过程,以便获得所需的结构。

enter image description here

在此处输入图片说明

If you want to see the raw plist file, right click on the plist file in the project navigator and choose "Open As | Source Code"

如果要查看原始 plist 文件,请在项目导航器中右键单击 plist 文件,然后选择“Open As | Source Code”

enter image description here

在此处输入图片说明

And you'll see the raw file

你会看到原始文件

enter image description here

在此处输入图片说明

And to get back to the editor view: right click on the file again and choose "Open As | Property List"

并返回编辑器视图:再次右键单击文件并选择“打开为|属性列表”

enter image description here

在此处输入图片说明