PropertyDecoder 0.1.1

PropertyDecoder 0.1.1

Podul-verbose 维护。



  • 作者:podul
  • podul

PropertyDecoder

CI Status Version License Platform

使用

  1. 首先导入模块
import PropertyDecoder
  1. 新建模型,并遵守 Decodable 协议
struct Test: Decodable {
    let a: String
    let b: Int
    let c: Int?
    let d: String?
    let f: Data
    let arr: [String]
    let dict: [String: SubTest]
    let test: SubTest
}

struct SubTest: Decodable {
    let sub: String?
}
  1. 使用
do {
    let list = try Property.decode(Test.self)
    _ = list.map{ print($0) }
  }catch {
    print(error)
  }

do {
    let list = try Test.decodeProperties()
    _ = list.map{ print($0) }
  }catch {
    print(error)
  }

输出

{label: a, type: String}
{label: b, type: Int}
{label: c, type: Optional<Int>}
{label: d, type: Optional<String>}
{label: f, type: Data}
{label: arr, type: Array<String>}
{label: dict, type: Dictionary<String, SubTest>}
{label: test, type: SubTest}

依赖要求

  • iOS 10.0+
  • Xcode 10.2+
  • Swift 5+

安装

Cocoapods

pod 'PropertyDecoder'

Swift 包管理器

dependencies: [
    .package(url: "https://github.com/podul/PropertyDecoder", from: "0.1.0")
]

作者

Podul, [email protected]

许可证

PropertyDecoder 适用于 MIT 许可证。更多信息请参阅 LICENSE 文件。