BeyovaJSON
BeyovaJSON 允许 Swift 4 中的 Coadable 使用任何 json。
安装
CocoaPods
pod 'BeyovaJSON'
Carthage
github "Beyova/BeyovaJSON"
用法
import BeyovaJSON
Codable
Codable
从Xcode 9、iOS 11和Swift 4开始被加入,用于让您的数据类型支持编码和解码,以便与JSON等外部表示形式兼容。
class Group: Codable {
var title: String = "Guardians of the Galaxy"
var members: JSON = [["name": "Star-Lord"],["name": "Groot"],["name": "Rocket"]]
var date: Date = Date()
}
let group = Group()
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(group)
print(String(bytes: data, encoding: .utf8)!)