Joh*_*ton 0 javascript object objective-c
在Javascript中,您可以创建一个多维对象(见下文).在Objective C中实现这一目标的正确方法是什么?
下面的这个对象代表游戏中的一个级别. 
var Levels = {
    Level1:{shapes:[{
  bodytype : "dynamic",
  h : "50.0000",
  nameid : "hofN7-1",
  props : {
    id : "properties"}
,
  rotation : "0.0000",
  type : "square",
  uid : "Av2EZQh",
  w : "50.0000",
  x : "20.0000",
  y : "20.0000"}
,
{
  bodytype : "dynamic",
  h : "50.0000",
  nameid : "hofN7-2",
  props : {
    gravMassScale : "2",
    id : "properties",
    inertia : "2",
    isBullet : true,
    torque : "2",
    velocity : {
      x : "2",
      y : "2"}
}...etc
这将是一个NSDictionary,NSStrings作为键,并为孩子们提供嵌套的NSDictionaries,NSStrings,NSArrays和NSNumbers的组合.
将代码机械转换为Objective-C语法将是:
NSDictionary *levels = @{
    @"Level1" : @{ @"shapes" : @[ @{
  @"bodytype" : @"dynamic",
  @"h" : @"50.0000",
  @"nameid" : @"hofN7-1",
  @"props" : @{
    @"id" : @"properties"}
,
  @"rotation" : @"0.0000",
  @"type" : @"square",
  @"uid" : @"Av2EZQh",
  @"w" : @"50.0000",
  @"x" : @"20.0000",
  @"y" : @"20.0000"}
,
@{
  @"bodytype" : @"dynamic",
  @"h" : @"50.0000",
  @"nameid" : @"hofN7-2",
  @"props" : @{
    @"gravMassScale" : @"2",
    @"id" : @"properties",
    @"inertia" : @"2",
    @"isBullet" : @YES,
    @"torque" : @"2",
    @"velocity" : {
      @"x" : @"2",
      @"y" : @"2"}
} …
| 归档时间: | 
 | 
| 查看次数: | 77 次 | 
| 最近记录: |