Codable
Encodable: Convert objects to Data.
Codable
Encodable: Convert objects to Data.
0
0
Checkbox to mark video as read
Mark as read

Just as we used the Decodable protocol to convert data into our objects, we can do the reverse conversion using the Encodable protocol.

struct Person: Encodable {
    let name: String
    let age: Int
}

let person: Person = Person(name: "Pablo", age: 23)
let data: Data? = try? JSONEncoder().encode(person)

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy