基于 Moya 和 PromiseKit 的网络请求层 SGAPIRequest

码农软件 · 软件分类 · 网络工具包 · 2019-02-24 19:28:46

软件介绍

SGAPIRequest 是用 Moya + PromiseKit 创建具有序列化及缓存功能的网络请求层。

第一次使用Swift来做项目,第一步当然就是折腾架构,由于项目时间比较宽裕,使用了较多的时间来进行学习参照,最后使用了这样的架构来作为这个产品的网络层,满足了项目基本的需求,肯定有不少的缺陷,权当各位参考。

先来看看最终我们要达成的目标,下面是一段异步请求接口的代码,这段代码具有网络请求、序列化及基本的缓存功能

firstly { () -> Promise<[ArticleCategoryModel?]?> in
    return CallApi(DFAPI.navigations, isCached: true)
}.then { [weak self] (data) -> Void in
    self!.navigations = data!
}

这一段请求,由以下4个库实现:

  1. Moya:负责网络请求

  2. PromiseKit:负责干净优雅的链式异步调用

  3. HandyJSON:负责序列化、反序列化

  4. AwesomeCache:负责缓存请求结果及缓存过期

项目Demo

本文地址:https://codercto.com/soft/d/54.html

Spark

Spark

Bill Chambers、Matei Zaharia / O′Reilly / 2017-10-31 / GBP 39.99

Learn how to use, deploy, and maintain Apache Spark with this comprehensive guide, written by the creators of the open-source cluster-computing framework. With an emphasis on improvements and new feat......一起来看看 《Spark》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具