iOS

Codable & JSON Parsing

Codable protocol, JSONEncoder, JSONDecoder, custom keys, nested JSON, date strategies

20 preguntas de entrevista·
Mid-Level
1

What is the Codable protocol in Swift?

Respuesta

Codable is a typealias combining Encodable and Decodable. It enables serialization and deserialization of Swift structures to/from JSON or other formats. It's the standard mechanism for handling JSON in iOS without external frameworks.

2

What is the difference between Encodable and Decodable?

Respuesta

Encodable serializes a Swift instance into JSON data (object to JSON). Decodable performs the reverse operation, converting JSON into a Swift instance. These protocols are orthogonal: a struct can implement one, the other, or both as needed.

3

What is the purpose of the CodingKeys enum during JSON decoding?

Respuesta

CodingKeys maps Swift properties to actual JSON keys. It handles naming mismatches between Swift code (camelCase) and JSON (snake_case). Without CodingKeys, property names must exactly match JSON keys.

4

How to create a JSONDecoder instance to decode JSON?

5

What does JSONEncoder.encode() return after successful serialization?

+17 preguntas de entrevista

Domina iOS para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis