我是 Objective C 的新手,在将 2d int 数组添加到 NSMutableDictionary 时遇到了麻烦。“不兼容的指针类型”的代码错误 - 我认为这是因为 setObject 会期待一个对象..
这是代码-我正在尝试使用包含我的级别数据的字典:
NSMutableDictionary *level = [[NSMutableDictionary alloc] init];
[level setObject:@"The Title" forKey:@"title"];
[level setObject:@"level_1" forKey:@"slug"];
int levelTiles[10][10] = {
{1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1}
};
[level setObject:levelTiles forKey:@"tiles"]; // THIS LINE FAILS
我有两个问题:
- 如何像这样将 int 数组(或类似数组)添加到字典中?
- 有没有更好的方法来初始化我的游戏数据?
谢谢你的帮助,
拉克兰