开发者

Is there a way to construct an object automatically from an NSDictionary?

开发者 https://www.devze.com 2023-01-22 00:21 出处:网络
I\'m building an iPhone app that communicates with an external server via JSON. The JSON library I\'m using parses the response string from the server into a dictionary. Currently I\'ve got a method t

I'm building an iPhone app that communicates with an external server via JSON. The JSON library I'm using parses the response string from the server into a dictionary. Currently I've got a method that I've written that just uses hardcoded strin开发者_如何学编程gs as keys for the dictionary in a constructor I've written called initWithDictionary:(NSDictionary *)dic (e.g. self.name = [dic valueForKey:@"name"];. Is there some smart idiomatic Objective-C way to do this?


Just call [someObject setValuesForKeysWithDictionary:dictFromJSON] to set an object's properties from a dictionary.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号