在使用 dictionaryWithObjectsAndKeys 初始化 NSMutableDictionary
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:value1, @"key1", value2, @"key2", value3, @"key3", nil];
可能会发现 dict 中没有3个key-value对,原因是 dictionaryWithObjectsAndKeys 遇到 object 为 nil 时结束。
解决方式是在 object 可能为 nil 下, 使用 setObject:forKey:
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:10];
[dict setObject:value1 forKey:@"key1"];
[dict setObject:value2 forKey:@"key2"];
[dict setObject:value3 forKey:@"key3"];