【发布时间】:2012-04-03 00:52:07
【问题描述】:
我正在尝试使用此功能在我的 iOS 应用中创建一个包含动物列表的 NSMutableDictionary。
// puts animals into dictionary
- (void) putAnimalsFromPlistToDictionary
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"myAnimals" ofType:@"plist"];
myAnimalDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
// I set a breakpoint here in XCode.
}
我将 myAnimals.plist(如下所示)拖到我的应用程序的支持文件夹中。
<?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>elephant</string>
<string>monkey</string>
<string>cat</string>
</array>
</plist>
但是,当我到达断点(如我的评论中所列)时,我看到 myAnimalDictionary 为 nil。为什么?
【问题讨论】:
标签: objective-c ios