Xcode创建中的plist [英] plist in Xcode creation

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

问题描述

当我为下面的链接创建一个简单的plist应用程序时:

When I am creating a simple application for plist shown in below link:

http://iosdevelopertips.com/data-file-management/reading-a-plist-into-an-nsarray.html

当我调试它时...我正在获取我的plist文件的路径。但是当我使用以下语句时

When I am debugging it.. I am getting path of my plist file. But when I am using the following statement

// Build the array from the plist  
NSMutableArray *array2 = [[NSMutableArray alloc] initWithContentsOfFile:path];

我在array2中没有任何价值......可能是什么问题?

I don't get any value in array2... What could be the problem?

推荐答案

这是我为plist提供的最终解决方案....

Here is the final solution that i got for plist....

当您使用第一个元素作为数组创建plist文件时,其XML内容将如下所示:

When u are creating your plist file with first element as Array.. then its XML Contents will be as below:

<?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">
<dict>
    <key>Root</key>
    <array>
        <string>Firecracker</string>
        <string>Lemon Drop</string>
        <string>Mojito</string>
    </array>
</dict>
</plist>

这里你有不必要的标签而不是我们应该拥有的标签,因为你的根元素必须是数组..因为你正在接受NSMutableArray对象......

Here you are having unnecessary tag instead of which we should have as your root element must be Array... because u are taking in NSMutableArray object...

所以你的plist文件必须是这样的

so your plist file must be like this

<?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>Firecracker</string>
        <string>Lemon Drop</string>
        <string>Mojito</string>
    </array>
</plist>

我已检查其工作正常....

i have checked that its working fine....

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

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