CodableModel

public protocol CodableModel : AnyModel, Decodable, Encodable

通用Codable模型协议,默认未实现KeyMappable,使用方式同Codable一致; CodableModel可实现KeyMappable,并选择以下模式使用,推荐方式

KeyMappable模式一:MappedValue模式

  1. 支持Codable类型字段,使用方式:@MappedValue
  2. 支持多字段映射,使用方式:@MappedValue(“name1”, “name2”)
  3. 支持Any类型字段,使用方式:@MappedValue
  4. 未标记MappedValue的字段将自动忽略,也可代码忽略:@MappedValue(ignored: true)

KeyMappable模式二:MappedValueMacro模式(需引入FWMacro子模块)

  1. 标记class或struct为自动映射存储属性宏,使用方式:@MappedValueMacro
  2. 可自定义字段映射规则,使用方式:@MappedValue(“name1”, “name2”)
  3. 以下划线开头或结尾的字段将自动忽略,也可代码忽略:@MappedValue(ignored: true)

KeyMappable模式三:自定义模式

  1. 需完整实现Codable协议的encode和decode协议方法

Available where Self: AnyObject

  • hashString Extension method

    获取对象的内存hash字符串

    Declaration

    Swift

    public var hashString: String { get }