使用 Moya + ObjectMapper/Codable/SwiftyJSON (三选一)封装的网络层,可以根据项目需要选择合适的方案
如何使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| //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) } }
|
##具体实现细节请查看源码 RainHttpManager