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

PropertyDecoder 0.1.1

PropertyDecoder 0.1.1

Maintained by Podul-verbose.



  • By
  • podul

PropertyDecoder

CI Status Version License Platform

Usage

  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)
  }

or

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}

Requirements

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

Installation

Cocoapods

pod 'PropertyDecoder'

Swift Package Manager

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

Author

Podul, [email protected]

License

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