How to Fetch Data From an API in Swift
Introduction Fetching JSON data from a remote API really is the bread and butter of iOS development so it’s important for you to know how to do it in a neat and reusable way. Today, we will be using Codable and URLSession. Oh, and some generics too. We will be using the website https://jsonplaceholder.typicode.com/todos. This handily provides us with some example JSON data that we can use. [ { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }, { "userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false } ] Defining Our Model To get started, we first need to define a model for the data....