मुझे 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);
}
और मैं निम्नलिखित लॉग बयान मिलता है:
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:
कहते हैं, मैं null
प्राप्त करें। मैंने परियोजना की सफाई के फॉलबैक विकल्प की भी कोशिश की है।
क्या किसी ने कभी इसमें भाग लिया है, या क्या मैं वास्तव में कुछ मूलभूत भूल गया हूं?
जिज्ञासा से, 'एडिक्ट' को सेट करने और लॉगिंग करने के बाद, यदि आप 'डीएलओजी (@ "% @", [एडिक्ट ऑलकेज़] करते हैं तो क्या होता है); '? – Isaac
क्या यह * वास्तविक * कोड है? किसी भी मौके पर आपने कुंजी को गलत टाइप किया है? 'डीएलओजी (@"% @ ", [एडिक्ट ऑलकेज़] क्या करता है) 'दे? –
आप 'new @' के बजाय '% p' के साथ 'newSourceString' को लॉगिंग करने का भी प्रयास करना चाहेंगे। –