我今天遇到了一个策略错误。我有一个 NSArray
和一个 NSMutableDictionary
。问题是我的 NSMutableDictionary
变成了一个数组。这是代码:
标题:
NSArray *tableViewCellValues;
NSMutableDictionary *inputValues;
实现:
- (void)viewDidLoad
{
[super viewDidLoad];
tableViewCellValues = [NSArray arrayWithObjects:@"First", @"Second", @"Third", nil];
inputValues = [NSMutableDictionary dictionary];
//other code...
}
所以通常我应该得到一个以“First”、“Second”和“Third”为对象的数组和一个空的 NSMutableDictionary
。当我在初始化 NSMutableDictionary
后立即在日志中打印它时,我得到以下信息:
(lldb) po tableViewCellValues
(NSArray *) $1 = 0x00000000 <nil>
(lldb) po inputValues
(NSMutableDictionary *) $2 = 0x06a80420 <__NSArrayI 0x6a80420>(
First,
Second,
Third
)
(lldb) po [tableViewCellValues class]
error: Couldn't execute function; result was eExecutionDiscarded
(lldb) po [inputValues class]
(id) $4 = 0x01453b64 __NSArrayI
我有点困惑。我尝试清理并再次运行它,但没有任何反应。
如果重要的话,我正在使用 Mac OS X 10.7.3 和 Xcode 4.3。
如有任何帮助,我们将不胜感激。
最佳答案
你真的想为你的字典分配内存,所以它应该是:
self.inputValues = [[NSMutableDictionary alloc] init];
关于iphone - NSMutableDictionary 没有正确初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11033752/