Swift 4 Decodable
Sep 9, 2018 · 1 min read
Today we will discuss how to implement swift Decodable to parse JSON data from a server in a few simple steps without any third-party libraries.
Our URL: https://rss.itunes.apple.com/api/v1/in/ios-apps/top-free/all/10/explicit.json
There are 2 steps in implementing Decodable
- Create structs according to the JSON data, let's say we need 10 top free app names, app images from the app store to display in our app, create struct according to our JSON data. ( we took iTunes RSS feed link because our aim is to show how we can easily achieve parsing bit complex JSON data. {{[{name:String}]}} )

2. Parse JSON using decodable.

//1: Creating appUrl
//2: Instantiate URLSession
//3: Creating decodedData using JSONDecoder.decode(structName, from: data received from server)
//4: As JSONDecoder can throw errors we need to handle errors.
//5: resume() does resume the task.