I\'m learning Swift lang and one of the things that would be great to hear others input about is \"How you handle models from JSON responses\"? For example -
I have
I would suggest using SwiftyJSONModel there your model would look something like:
import SwiftyJSONModel
class User: NSObject, JSONObjectInitializable {
enum PropertyKey : String {
case user_token, email
}
var user_token:String?
var email:String?
required init(object: JSONObject) throws {
user_token = object.value(for: .user_token)
email = object.value(for: .email)
}
}
This library has 3 nice things:
String
as library will infer the typeenum
which gives you auto-complition when you type the keys and guarantees that you cannot access keys, that are not in enum