SuperCodable 1.1.0

SuperCodable 1.1.0

lacklock 维护。



  • lacklock

SuperCodable

安装

pod 'SuperCodable'

Rx: 支持 Variable 解码

如果要将值解码为 Variable,请安装

pod 'SuperCodable/Rx'

使用方法

extension Int: DecodeFailable {
    public static var decodeFailedValue: Int { return 0 }
}

struct VariableModel: Codable {
    let code: Variable<Int>
    var stringValue: Variable<String?>
}

如果声明了 Variable 类型属性,我们认为您不希望 Variable 为可选。而不是可选属性,您希望将其改为可选 Element。如果 Element 为 Optional,则将按您的意愿工作。如果 Variable 内部 Element 不是 Optional,则应将 Element 类型符合 DecodeFailable。一旦 Variable 属性解码失败,将使用 DecodeFailable.decodeFailedValue 来初始化 Variable。

受以下启发