0

我有一个名为“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

不知道为什么将“名称”指出为“无法识别的选择器”。“名称”是我声明并正在使用的“会话”类的 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
4

2 回答 2

1
-[__NSDictionaryM name]: unrecognized selector sent to instance 0x1c5fb2d0

这意味着您正在尝试调用namewhereNSMutableDictionary您应该在 class 的对象上调用它SessionObject。检查您调用类似myObject.nameor的行[myObject name],看看是否myObject属于 typeSessionObject和 not NSMutableDictionary

这里__NSDictionaryM表示NSMutableDictionary类型。

于 2013-02-21T01:16:10.833 回答
0

我不确定你的错误来自哪里 - 但你在那里做什么?你为什么不写

sessionsInThatDayArray = [myScheduleFullDictionary objectForKey:targetDayString];

???这就是 NSDictionary 的用途——你不需要手动搜索,你只需调用方法来查找密钥。取而代之的是,您复制了字典,提取了所有键,对键进行了排序,逐个遍历它们直到找到它-然后调用了 objectForKey !!!

除此之外,在调试器中为所有 Objective-C 异常设置断点。当调用有问题的代码时它会停止,所以不需要大海捞针。

于 2014-02-13T19:06:30.763 回答