Plist数组NSArray没有对象
所以我search了,之前已经成功地读过了,但是却遇到了这个问题。
我有一个plist,是一串string。 我没有得到任何对象被读入数组。 我成功地做了这个在另一个控制器的字典。 所以这里是我的代码。
// Open plist and get brands NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"brands" ofType:@"plist"]; NSFileManager *fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:plistPath]) { NSLog(@"The file exists"); } else { NSLog(@"The file does not exist"); } _brands = [NSArray arrayWithContentsOfFile:plistPath]; _catList = [[[NSMutableArray alloc] initWithCapacity:[_brands count]] autorelease];
这是我的plist。 请注意_brands数组被定义为NSArray *品牌,属性设置为非primefaces,只读,并被合成为品牌= _brands。
<?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>Brand A</string> <string>Brand B</string> <string>Brand C</string> <string>Brand D</string> </array> </dict> </plist>
我看到有一个标签,但在Xcode中,它显示为一个string数组。 不是一个字典>数组>多个string
版主是他们心中的字典(注意<dict>标签)。 将文件读入一个NSDictionary,然后使用objectforKey:
方法和Root
键向字典索要数组。
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:plistPath]; _brands = [dict objectForKey:@"Root"];
NSString *plistPath = [self copyFileToDocumentDirectory:plistFileName]; NSDictionary *plistContents=[[NSDictionary alloc] initWithContentsOfFile:plistPath]; [plistPath release]; return plistContents;
- 在Swift中逐步实现委托。
- 新改版的iOS应用客户评论部分在哪里(2015年9月)iTunes连接用户界面
- CocoaPods podspec lint failure – 找不到文件
- 在UIPageViewController中更改页面自动使用swift 3中的计时器?
- NSNotificationCenter:不是自我的addObserver
- 在Xcode7.0中手动安装模拟器SDK 8.0
- iOS背景下载,带有无提示通知iOS 11
- 如果还使用iOS,则Google Play Services 8.4.0会打破Google Cloud Messaging for Android
- 当应用程序在后台运行时,在iOS应用程序的locking屏幕上添加图像