Swift Generic JSON Type
此软件包提供了一个简单的容器来存储任何符合Codable
协议的JSON数据。
当您想要将返回JSON数据的函数结果发送为Decodable
到另一个接受JSON数据的Encodable
函数时使用此软件包;例如,如果您想要将Marionette
的evaluate
函数的结果发送到JSBridge函数。
安装
SwiftPM
dependencies: [
.package(url: "https://github.com/LinusU/GenericJSONType", from: "1.0.0"),
]
Carthage
github "LinusU/GenericJSONType" ~> 1.0.0
用法
import GenericJSONType
let myJSONString = " ~~ any valid JSON string here ~~ ".data(using: .utf8)!
let decoder = JSONDecoder()
let decoded = try decoder.decode(JSON.self, from: myJSONString)
// `decoded` is now a structure representing the JSON data
let encoder = JSONEncoder()
let encoded = try encoder.encode(decoded)
// `encoded` is now a JSON representation of the data we started out with
黑客攻击
使用 XcodeGen 从 project.yml
自动生成 Xcode 项目。仅因为 Carthage 需要它,所以进行了提交,请勿手动编辑。
$ mint run yonaskolb/xcodegen
💾 Saved project to GenericJSONType.xcodeproj