我正在尝试这段代码,
NSString *titleOfPlace = [place objectForKey:@"name"];
NSString *reference = [place objectForKey:@"reference"];
[placesExtraInfo setObject:reference forKey:titleOfPlace];
NSLog(@"%@", (NSString *)[placesExtraInfo objectForKey:titleOfPlace]);
输出是
2011-11-21 10:06:49.536 Tittle-Tattle[25545:1bb03] 0
2011-11-21 10:06:49.554 Tittle-Tattle[25545:1bb03] (null)
2011-11-21 10:06:49.555 Tittle-Tattle[25545:1bb03] (null)
2011-11-21 10:06:49.555 Tittle-Tattle[25545:1bb03] (null)
2011-11-21 10:06:49.555 Tittle-Tattle[25545:1bb03] (null)
.... about 20 of them as I had 20 objects to add...
我究竟做错了什么?
PS当我的NSlog
titleOfPlace
和reference
值比它打印完美时。为何不将其保存在NSMutableDictionary中?感谢您的任何输入!
更新
title John's Grill
reference CnRkAAAAmyHKGYtr9brX5uJEwlyK791oCWErzrY8hKjFX2eXBV5hrrbVjE_-CPvCfoxUpu4TiXswTXUtvP_UkYG2p4RG2a1oc_4HSxku1jIlVx0H4LZgo_SQbUMSrJ1xDvwxxWVsyWtEjxCIF6qma_slsFSLphIQmSnwBgYQATX46MXkuW0s5BoUGM0K_KRvH_gbc4k-TSsSpgnQyTk
please no null (null)
2011-11-21 10:19:40.339 Tittle-Tattle[30277:1bb03] title Fifth Floor
reference CnRiAAAAtzTFHqqcAMyYzuKSq7nwHdt9e-lnP1W4i6pyUGQiomT0SvqDm1RWxhH05fJpqMJ9RdU8QHO-g7-EXgVHQnoms_bip5gGXdE96SCN7HQW5-Y69K7144VvgnOATVVNZRWQgyNZ2NNYRSltVuL61UXg7BIQ8YinfdZ6Ahq2lU6XhNVQ7hoU2IwUAHKcGHELPeYgbshPmiS9nOA
please no null (null)
2011-11-21 10:19:40.339 Tittle-Tattle[30277:1bb03] title Ghirardelli Chocolate
reference CnRsAAAAkHnx_nYhhe4QnV2jQyWdU5Vb387rFdVlhPcsnp6ZUjEroEzRLCcYO687ybSlTqSMDP5BxJVeehgUt9kkL97l1puos89e2HT85t-H5VWl7G0qZ0M_IoL0Gp3VmKl07MQRFt0_zdXesSVjSzLFRpBDChIQwcpeapYjGYq8jSQTZUmoMxoUSS1M0rBvMkqKSRRGMpWlyWbHUJ0
please no null (null)
最佳答案
正如我在上面的评论中所说,请确保placesExtraInfo
不是nil
(如果将objectForKey:
发送到nil
,它将返回nil
)。
关于iphone - 为什么我的NSMutableDictionary在setObject中为null?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8205571/