再Alamofire的基础上封装了一套网络请求,并且实现数据解析的工具库,配合RxSwift使用起来非常方便
- Xcode 9.0+
pod 'NetWorkCore', '~> 0.0.1'
NetWorkAPI.sharedInstance.requestSwiftyJSONReg(Api.topics) { (result) in
switch result {
case .success(let repos):
print(repos)
case .failure(let error):
print(error)
}
}
Observable.just("")
.map { _ in Api.topics}
.emeRequestApiForJson().subscribe(onNext: {(result) in
switch result {
case .success(let data):
print(data)
case .failure(let error):
print(error)
}
})
.disposed(by: disposeBag)
在发起网络请求之前需要配置下
//正确码 即:successCode 为1 的时候才会解析dataKey字段的值得
NetWorkCore.successCode = 1
// 获取successCode的建是对应的success
NetWorkCore.statusKey = "success"
// 获取data中的数据
NetWorkCore.dataKey = "data"
发起网络请求
Observable.just("")
.map { _ in Api.topics}
.emeRequestApiForArray(TopicsModel.self)
.subscribe(onNext: {(result) in
switch result {
case .success(let data):
print(data)
case .failure(let error):
print(error)
}
})
.disposed(by: disposeBag)
func request3() {
Observable.just("")
.map { _ in Api.topics}
.emeRequestApiForArray(TopicsModel.self)
.subscribe(onNext: {(result) in
switch result {
case .success(let data):
print(data)
case .failure(let error):
print(error)
}
})
.disposed(by: disposeBag)
}