关于XCode 4中读取Plist文件

    关于XCode 4中读取Plist文件是本文要介绍的内容,主要介绍的是plist文件图和来获取,内容不多,主要是通过代码来实现。不多说,先来看详细内容。

 

1. 添加plist文件

 

2. 代码读取

// Path to the plist (in the application bundle)
NSString *path = [[NSBundle mainBundle] pathForResource:@"DrinkArray" ofType:@"plist"];
// Build the array from the plist
NSMutableArray *array2 = [[NSMutableArray alloc] initWithContentsOfFile:path];
// Show the string values
for (NSString *str in array2)
    NSLog(@"--%@", str);

其中array2总是为空,原因:选中DrinkArray.plist,ctrl + click(或右键,如果有鼠标) open as->source code, 结果如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DObjective-CTYPE 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>

解决方法,手工修改成:

<?xml version="1.0" encoding="UTF-8"?>
<!DObjective-CTYPE 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>

小结:关于 XCode 4中读取Plist文件的内容介绍完了,希望通过本文的学习能对你有所帮助!

原文地址:http://mobile.51cto.com/iphone-281907.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值