2016-07-29 48 views
0

我有一個對象,它具有多個對象如何獲得鬍子

fields:[ 
    { 
    safeName: 'status', 
    accessorName: 'Status', 
    type: {name: 'String', doc: 'String', code: '\'String\''}, 
    field: {type: 'string', description: 'pet status in the store', enum: ['available', 'pending', 'sold']} 
    }, 
    { 

    safeName: 'code', 
    accessorName: 'Code', 
    type: {name: 'NSInteger', doc: 'NSInteger', code: '\'NSInteger\'' }, 
    field: {type: 'integer', format: 'int32'} 
    }, 
    ... 
] 

我需要檢查枚舉值獲取一個節點的值

輸出應該是

enum存在於字段

instance.status = Order.Status(rawValue: (sourceDictionary["status"] as? String) ?? "")

enum is not presentfield對象

instance.code = Decoders.decodeOptional(clazz: NSInteger.self, source: sourceDictionary["code"])

回答

0

難道這樣

{{#fields}}{{#field}} 
    {{#description}} 
    instance.{{safeName}} = Order.Status(rawValue: (sourceDictionary["{{safeName}}"] as? String) ?? "") 
    {{/description}} 
    {{^description}} 
    instance.{{safeName}} = Decoders.decodeOptional(clazz: {{#type}}{{type.name}}{{/type}}.self, source: sourceDictionary["code"]) 
    {{/description} 
{{/field}}{{/fields}}