出於某種原因,我無法將數組添加到nsmutableDictionary中。我把它宣佈爲在我的.h文件中的屬性:iOS:NSMutableDictionary propery不會設置
@interface TCMExhibitFeedStore : NSObject
@property (nonatomic, strong) NSMutableDictionary *allLevels;
@property (nonatomic, strong) NSMutableDictionary *storedLevels;
+ (TCMExhibitFeedStore *)sharedStore;
- (void)fetchExhibtFeedWithCompletion:(void (^)(NSMutableDictionary *obj, NSError *err))block;
- (TCMLevel *)createLevel:(TCMLevelRemote *)l;
- (TCMExhibit *)createExhibit:(TCMExhibitRemote *)e;
- (BOOL)saveChanges;
@end
然後,我想一個空數組中的.m文件添加到它的功能,這樣
[_storedLevels setObject:[[NSMutableArray alloc] init] forKey:@"levels"];
但是,當我通過應用程序時,這永遠不會被添加。看調試器顯示爲
_storedLevels NSMutableDictionary * 0x00000000
NSMutableDictionaries對我來說並不新鮮。我只是有點瘋狂,試圖找到我的錯誤,因爲這一切對我來說都很正常。
上面一行嘗試將可變數組設置爲字典_storedLevels中的鍵「levels」的值。然而,它失敗了,因爲_storedLevels是零,從未被初始化過。 (請注意,在調試時嘗試「將菊花鏈」語句連接在一起是非常愚蠢的,特別是如果您不真正瞭解自己在做什麼,請對每條語句執行一個操作,並將每條語句放在一個單獨的行中。) –