定义上下文
extension String {
static let decodeContext = DecodeContext<SwiftyJSON.JSON, String> { json in
return json.string
}
}
解码
let id = try Decoder(String.decodeContext, json["id"]).get()
DecodeContext 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 即可
pod "DecodeContext"
muukii,[email protected]
DecodeContext 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。