使用 Moya + ObjectMapper/Codable/S
作者:
罗同学_ | 来源:发表于
2018-05-11 11:33 被阅读276次
使用 Moya + ObjectMapper/Codable/SwiftyJSON (三选一)封装的网络层,可以根据项目需要选择合适的方案
如何使用
//1.json
RainHttpManager.requestJSON(ApiTest.fetchTestJSON, success: { (response) in
// json response
}) { (error) in
self.showErrorHUD(error.message)
}
//2.model
RainHttpManager<ApiTest, TestModel>.requestModel(.fetchTestModel, success: { (model) in
guard let model = model else {
return
}
print("name: \(model.name)")
}) { (error) in
self.showErrorHUD(error.message)
}
//3.model list
RainHttpManager<ApiTest, TestModel>.requestModelList(.fetchTestModelList(pageIndex: 0, pageSize: 10), authType: .basic, success: { (models) in
guard let models = models else {
return
}
print(models)
}) { (error) in
self.showErrorHUD(error.message)
}
}
本文标题:使用 Moya + ObjectMapper/Codable/S
本文链接:https://www.haomeiwen.com/subject/nicfdftx.html
网友评论