在AS3中,如果我想快速地设置一些数据来着,我只想做这样的事情工作...
In AS3 if I wanted to quickly setup some data to work with, I would just do something like this...
static var playerData:Object = {position:{startX:200, startY:200}};
我将如何创建目标C一样的吗?
How would I create the same in Objective c?
Or..is有没有更好的方式来在对象 - 存储相似的结构?
Or..is there a better way to store a similar data structure in Obj-c?
需要明确的是,我不是在Objective-C的专家,所以也许有些Objective-C的大师能帮助你比我好的。但我认为,你可以使用的NSMutableDictionary
模拟对象
AS3的行为:
To be clear, I'm not an expert in Objective-C, so maybe some Objective-C guru can help you better than I can. But I think that you can use NSMutableDictionary
to simulate the Object
AS3 behaviour:
id playerData = [[NSMutableDictionary alloc] init];
id position = [[NSMutableDictionary alloc] init];
[position setObject:@"200" forKey:@"startX"];
[position setObject:@"200" forKey:@"startY"];
[playerData setObject:position forKey:@"position"];
如果在AS3访问为:
playerData.position.startX
在Objective-C中,你可以做这样的事情:
In Objective-C you can do something like this:
[[playerData objectForKey:@"position"] objectForKey:@"startX"];