PropertyDecoder
Usage
- 首先导入模块
import PropertyDecoder- 新建模型,并遵守
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?
}- 使用
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.