我知道我可能做了一些非常愚蠢的事情,但我无法弄清楚这段代码的错误在哪里:
NSString *string=@"some string";
[self.dataResponse setValue:string forKey:@"Code"];
我也试过:
NSString *string=@"some string";
[self.dataResponse setObject:string forKey:@"Code"];
但在这两种情况下,我的 nsmutable 字典 self.dataResponse 都是空的。你们有谁知道我做错了什么吗?
非常感谢您的帮助。
最佳答案
您需要分配和初始化 NSMutableArray 以在其中设置值。示例:
self.dataResponse = [[NSMutableArray alloc] init]; // This is alloc and init
NSString *string = @"Some Val";
[self.dataResponse setValue:string forKey:@"Code"];
关于iphone - 当我设置值和 forKey 时,iOS NSMutabledictionary 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15843478/