我将如何创建目标C这个AS3数据结构? [英] How would I create this AS3 data structure in objective c?
本文介绍了我将如何创建目标C这个AS3数据结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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"];
这篇关于我将如何创建目标C这个AS3数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文