문자열이 사전에 있더라도 이 null
이고 NSString
인 경우 문제가 발생합니다. 여기에 코드입니다 :objectForKey :가 올바른 문자열로 null을 반환하게하는 원인은 무엇입니까?
- (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);
}
는 그리고 난 다음 로그 문을 얻을 :
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)
당신이 볼 수 있듯이, 문자열이 키 newSource
에서 사전에 아직 나는 objectForKey:
를 호출 할 때, I null
을 얻으십시오. 나는 심지어 프로젝트를 청소하는 대체 옵션을 시도했다.
누구도이 문제를 겪어 본 적이 없습니까? 아니면 단지 기본적인 것을 잊어 버렸습니까?
'aDict'를 설정하고 로깅 한 후,'DLog (@ "% @", [aDict allKeys]); – Isaac
* 실제 코드입니까? 열쇠를 잘못 입력했을 가능성이 있습니까? 'DLog (@ "% @", [aDict allKeys])가주는 것은 무엇입니까? –
'% @' 대신'newSourceString'을'% p'로 로깅하려고 할 수도 있습니다. –