BeyovaJSON allows any json for Coadable in Swift 4.
pod 'BeyovaJSON'
github "Beyova/BeyovaJSON"
import BeyovaJSON
Codable
is added with Xcode 9, iOS 11 and Swift 4.
It is used to make your data types encodable and decodable for compatibility with external representations such as 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)!)