我需要带上一个ARRAY
位于 .plist 上的字符串。我正在制作一个单例以使其更容易。这是我的 plist 的一个例子。
<plist version="1.0">
<array>
<dict>
<key>id</key>
<integer>1</integer>
<key>Texts</key>
<array>
<string>Text number one</string>
<string>Text number two</string>
<string>Text number three</string>
</array>
</dict>
<dict>
<key>id</key>
<integer>2</integer>
<key>Texts</key>
<array>
<string>Text number one</string>
<string>Text number two</string>
<string>Text number three</string>
</array>
</dict>
</array>
</plist>
这是我带来字符串数组的方法:
- (NSArray*)getStoryTutorialForEnvironmentId:(int)envId andPage:(int)pageNumber{
NSArray* storyArray = [self.tutorial objectAtIndex:envId];
NSDictionary* gamingVoicesArray = [storyArray objectAtIndex:pageNumber];
NSArray *finalArray = [gamingVoicesArray objectForKey:@"Texts"];
return finalArray;
}
问题是,我要崩溃了。我不知道如何制作我的最终数组以便在调用单音时返回文本数组。我做错了什么?
编辑: 崩溃日志-[__NSCFDictionary objectAtIndex:]:无法识别的选择器发送到实例 0xaa49e70
编辑2:
- (id)init{
self = [super init];
if (self != nil) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"StoryText"] != nil) {
NSArray* environment_story_temp = [defaults objectForKey:@"MyPlist"];
self.tutorial = [[NSMutableArray alloc] initWithArray:environment_story_temp];
}else{
NSString* plistPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"MyPlist.plist"];
if (plistPath != nil) {
self.tutorial = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
[defaults setObject:self.tutorial forKey:@"MyPlist"];
[defaults synchronize];
}
}
}
return self;
}