CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

MMCodable 0.0.2

MMCodable 0.0.2

Maintained by LinXunFeng.



MMCodable 0.0.2

MMCodable

Author Build Status Version Carthage License Platform

MMCodable 是从 MoyaMapper 里分离出来的,基于 SwiftyJSON 对官方 Codable 进行强化的协议。无须关心原 json 数据中的类型,最终解析出来的类型由开发者决定!

Requirements

  • iOS 8.0+

  • Swift 5.0+

Feature

  • 无视 json 中值的类型,Model 中属性声明的是什么类型,它就是什么类型

Usage

使用方式跟 Codable 一致,只是多了一个 mapping 方法,方便进行额外的数据和类型的映射

import MMCodable
import SwiftyJSON

struct AModel: MMCodable {
    var name: String = ""
    mutating func mapping(_ json: JSON) {
        name = json["aname"].stringValue
    }
}

Installation

Cocoapods

pod 'MMCodable'

Carthage

在你的 Cartfile 文件中添加如下内容:

github "MoyaMapper/MMCodable"

接着运行 carthage update --platform ios.

Author

License

MMCodable is available under the MIT license. See the LICENSE file for more info.