MappedCodableModel
public protocol MappedCodableModel : CodableModel
模型可实现MappedCodableModel键名映射协议,并选择以下模式使用,推荐方式
模式一:MappedValue模式
- 支持Codable类型字段,使用方式:@MappedValue
- 支持多字段映射,使用方式:@MappedValue(“name1”, “name2”)
- 支持Any类型字段,使用方式:@MappedValue
- 未标记MappedValue的字段将自动忽略,也可代码忽略:@MappedValue(ignored: true)
模式二:MappedValueMacro模式(需引入FWPluginMacros子模块)
- 标记class或struct为自动映射存储属性宏,使用方式:@MappedValueMacro
- 可自定义字段映射规则,使用方式:@MappedValue(“name1”, “name2”)
- 以下划线开头或结尾的字段将自动忽略,也可代码忽略:@MappedValue(ignored: true)
模式三:自定义模式
- 需完整实现Codable协议的encode和decode协议方法
-
encode(to:
Extension method) Declaration
Swift
public func encode(to encoder: Encoder) throws
-
init(from:
Extension method) Declaration
Swift
public init(from decoder: Decoder) throws
-
encodeMirror(to:
Extension method) Undocumented
Declaration
Swift
public func encodeMirror(to encoder: Encoder) throws
-
decodeMirror(from:
Extension method) Undocumented
Declaration
Swift
public func decodeMirror(from decoder: Decoder) throws