【发布时间】:2013-02-12 00:33:24
【问题描述】:
我有一个名为“myScheduleFullDictionary”的 NSMutableDictionary,设置如下:
KEY VALUE
"Day 1" An NSMutableArray of NSMutableDictionaries
"Day 2" An NSMutableArray of NSMutableDictionaries
"Day 3" An NSMutableArray of NSMutableDictionaries
等等
我正在尝试解析它 - 基本上抓取其中一个 MutableArrays 作为其中一个键的值。 这是我的代码:
// First I make a mutableCopy of the entire Dictionary:
NSMutableDictionary *copyOfMyScheduleDictionary = [myScheduleFullDictionary mutableCopy];
// Next I grab & sort all the KEYS from it:
NSArray *dayKeysArray = [[copyOfMyScheduleDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
// I set up an NSMutableArray to hold the MutableArray I want to grab:
NSMutableArray *sessionsInThatDayArray = [[NSMutableArray alloc] init];
// Then I iterate through the KEYs and compare each to the one I'm searching for:
for (int i = 0; i < [dayKeysArray count]; i++) {
NSString *currentDayKey = [dayKeysArray objectAtIndex:i];
if ([currentDayKey isEqualToString: targetDayString]) {
NSLog(@"FOUND MATCH!!!");
// I log out the NSMutableArray I found - which works perfectly:
NSLog(@"found array is: %@", [copyOfMyScheduleDictionary objectForKey:currentDayKey]);
// But when I try to actually grab it, everything crashes:
sessionsInThatDayArray = [copyOfMyScheduleDictionary objectForKey:currentDayKey];
break;
}
}
我得到的错误是:
-[__NSDictionaryM name]: unrecognized selector sent to instance 0x1c5fb2d0
不确定为什么将“名称”指出为“无法识别的选择器”。 “name”是我声明并正在使用的“Session”类的 NSString 属性 - 可以以某种方式相关吗?
有什么见解吗?
编辑:
这是我的“SessionObject”类定义:
@interface SessionObject : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *speaker;
@property (nonatomic, strong) NSString *location;
@property (nonatomic, strong) NSDate *startTime, *endTime;
@property (nonatomic, strong) NSString *notes;
@property (nonatomic, strong) NSString *dayOfConference;
@end
【问题讨论】:
-
name用在哪里了? -
你确定这是导致错误的行吗?是否添加了异常断点?日志应该有效,但下一行无效。
-
如何添加异常断点?你的意思是 try-catch 块?
-
在 Xcode 的断点侧边栏中,在底部,有一个加号。您可以通过它添加异常断点。它们是一旦抛出异常就会触发的断点(与@catch 完全不同)。
-
等待。我想你是正确的。我认为它毕竟崩溃了。等等……
标签: iphone objective-c nsmutablearray nsmutabledictionary