我有一个对象,它有多个对象
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 present
对象中的field
instance.code = Decoders.decodeOptional(clazz: NSInteger.self, source: sourceDictionary["code"])
答案 0 :(得分: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}}