MMCodable是从MoyaMapper里分离出来的,基于SwiftyJSON对官方Codable进行强化的协议。无须关心原json数据中的类型,最终解析出来的类型由开发者决定!
-
iOS 8.0+
-
Swift 5.0+
- 无视
json中值的类型,Model中属性声明的是什么类型,它就是什么类型
使用方式跟 Codable 一致,只是多了一个 mapping 方法,方便进行额外的数据和类型的映射
import MMCodable
import SwiftyJSON
struct AModel: MMCodable {
var name: String = ""
mutating func mapping(_ json: JSON) {
name = json["aname"].stringValue
}
}pod 'MMCodable'在你的 Cartfile 文件中添加如下内容:
github "MoyaMapper/MMCodable"
接着运行 carthage update --platform ios.
- LinXunFeng
- email: [email protected]
- Blogs: LinXunFeng‘s Blog | 掘金 | 简书
MMCodable is available under the MIT license. See the LICENSE file for more info.