【发布时间】:2012-06-03 21:59:16
【问题描述】:
我正在尝试使用initWithContentsOfFile 将plist 文件读入NSArray,如here 所述
我的代码是这样的
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:
@"routes" ofType:@"plist" ];
routes = [[NSArray alloc] initWithContentsOfFile:plistPath ];
NSLog:(@"contents of myArray %@", routes);
routes.plist 内部有一个非常简单的数组结构和 2 个字符串值
<?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>1</string>
<string>2</string>
</array>
</dict>
</plist>
一切似乎都很好。 plistPath 用正确的值初始化,这意味着文件被复制到包中并且可以读取。但是routes = [[NSArray alloc] initWithContentsOfFile:plistPath ]; 返回0x0 值。我认为这等于nil
我的代码有什么问题?
【问题讨论】:
标签: objective-c ios5 xcode4 xcode4.2