Problems with adding objects to NSMutableDictionary

萝らか妹 提交于 2019-12-01 21:34:34

The problem may be that you haven't initialized your varsLoaded by saying self.varsLoaded = [NSMutableDictionary dictionary];

So you're adding objects to a non-existing dictionary, but you're not getting an exception because this is normal in objective-c :)

You should really check the response before processing any further. Wrap it in something like this:

if (response == nil) {
    // Check for problems

}
else {
     NSString *value = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        [varsLoaded setObject:value forKey:var];
}

Change the first line of your code from NSArray to NSMutableArray and see if you have better luck.

It doesn't matter that you declared your varsLoaded as a NSMutableDictionary somewhere else... in the local context of that code above, the compiler believes varsToLoad is a immutable array and probably isn't even compiling your setObject: forKey: line. You're not getting warnings in the build log or in the console while you're running??

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!