美文网首页
UserExtension.swift

UserExtension.swift

作者: 幸运的小强本人 | 来源:发表于2016-03-06 21:23 被阅读7次
extension User: JSONDecodable {
    static func create(id: Int)(name: String)(email: String) ->User {
        return User(id: id, name: name, email: email)
    }

    static func decode(json: JSON)->User? {
        return _JSONObject(json) >>> { d in
            User.create <^>
                    d["id"] >>> _JSONInt <*>
                    d["name"] >>> _JSONString <*>
                    d["email"] >>> _JSONString
        }
    }
}

网友评论

      本文标题:UserExtension.swift

      本文链接:https://www.haomeiwen.com/subject/yyuakttx.html