设为首页 加入收藏

TOP

基于Moya、RxSwift和ObjectMapper优雅实现REST API请求(三)
2019-09-18 11:11:32 】 浏览:168
Tags:基于 Moya RxSwift ObjectMapper 优雅 实现 REST API 请求
)") }catch{ print(error) } do{ let users = try provider.rx.request(.userQuery(keyword: "Wiki")).mapArray(type: User.self).toBlocking().first() print("test8 users.count = \(users?.count)") }catch{ if error is ServiceError { print((error as! ServiceError).message) } print(error) }

打印日志

private func JSONResponseDataFormatter(_ data: Data) -> Data {
    do {
        let dataAsJSON = try JSONSerialization.jsonObject(with: data)
        let prettyData =  try JSONSerialization.data(withJSONObject: dataAsJSON, options: .prettyPrinted)
        return prettyData
    } catch {
        return data // fallback to original data if it can't be serialized.
    }
}
let provider = MoyaProvider<MyApiService>(plugins: [NetworkLoggerPlugin(verbose: true, responseDataFormatter: JSONResponseDataFormatter)])
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS开发用如何用类"SKStoreP.. 下一篇解决:target overrides the `GCC..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目