什么会导致objectForKey:返回null并且有一个有效的字符串?

the*_*wan 7 cocoa objective-c nsdictionary nsstring

我有一个问题,NSDictionary返回null一个NSString即使字符串是字典中.这是代码:

- (void)sourceDidChange:(NSNotification *)aNote {
    NSDictionary *aDict = [aNote userInfo];
    DLog(@"%@", aDict);
    NSString *newSourceString = [aDict objectForKey:@"newSource"];
    DLog(@"%@", newSourceString);
    newSourceString = [newSourceString stringByReplacingOccurrencesOfString:@" " withString:@""];
    DLog(@"%@", newSourceString);
    NSString *inspectorString = [newSourceString stringByAppendingString:@"InspectorController"];
    DLog(@"%@", inspectorString);
    newSourceString = [newSourceString stringByAppendingString:@"ViewController"];
    DLog(@"%@", newSourceString);
}
Run Code Online (Sandbox Code Playgroud)

我得到以下日志声明:

2010-04-17 23:50:13.913 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] { newSource = "Second View"; }
2010-04-17 23:50:13.914 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
2010-04-17 23:50:13.916 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
2010-04-17 23:50:13.917 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
2010-04-17 23:50:13.917 CoreDataUISandbox[13417:a0f] -[RightViewController sourceDidChange:] (null)
Run Code Online (Sandbox Code Playgroud)

如你所见,字符串在键下的字典中newSource,但是当我打电话时objectForKey:,我得到了null.我甚至尝试过清理项目的后备选项.

有没有人碰到这个,或者我只是忘记了一些非常基本的东西?

Tec*_*Zen 3

此时,由于某种原因,DLog 会报告错误。

尝试:

  1. 使用 NSLog 进行日志记录。
  2. newSourceString当代码处于活动状态时,直接在调试器中检查 的值。