August 2025
Intermediate to advanced
270 pages
6h 16m
English
To make it easier to work with dynamic data, we can decode the JSON response into a concrete model. With the help of Decodable, you can parse this JSON with a single line of code.
Create a new Swift file in the Models folder and name it Hike. Inside, create a new struct with the properties from the JSON payload, conforming to the Decodable protocol.
| | struct Hike: Decodable { |
| | let name: String |
| | let latitude: Double |
| | let longitude: Double |
| | } |
Remember how Marker in the view required a coordinate? To do this, create a computed property for Hike that exposes the latitude and longitude as a CLLocationCoordinate2D. Make sure to import ...
Read now
Unlock full access