REST API and JSON in iOS: Build Weather App with REST API and Parse JSON in iOS


Most apps in the world now need to download, post or even delete some data from the Internet.

How do apps like Facebook, Instagram, Yelp work?

They all use REST APIs and JSON.

REST stands for REpresentational State Transfer.

API is Application Programming Interface.

And JSON is JavaScript Object Notation.

In this training, you’ll learn about RESTful API, how to make network calls, how to build network stack using URLSession and URLRequest in iOS, how to parse JSON in iOS.

Parse JSON is the task that every developer needs to know. So does making network calls with REST APIs.

Join me in this training and build the weather app!


Code Mastery is hosted by Duc Tran, founder of Developers Academy.

This is his free-style no notes, no teleprompter presentation and live coding broadcast with you guys everyday.

To join Duc’s free courses, register for free at


Duc Tran is founder of Developers Academy, one of the world’s leading iOS, Android and Web development trainers.

More than 2,000,000 developers have studied his video trainings; 100,000 developers see his posts each month. Each year, Duc has helped 20,000 plus developers graduate from his online courses or video series.

To subscribe and get free tutorials, courses and weekly content, visit me at:
Connect with Duc on facebook:
Tweet him:
Get daily inspiration:



class NetworkProcessor
lazy var configuration: URLSessionConfiguration = URLSessionConfiguration.default
lazy var session: URLSession = URLSession(configuration: self.configuration)

let url: URL

init(url: URL)
self.url = url

typealias JSONDictionaryHandler = (([String : Any]?) – Void)

func downloadJSONFromURL(_ completion: @escaping JSONDictionaryHandler)
let request = URLRequest(url: self.url)
let dataTask = session.dataTask(with: request) { (data, response, error) in

if error == nil {

if let httpResponse = response as? HTTPURLResponse {
switch httpResponse.statusCode {
case 200:
// successful response
if let data = data {
do {
let jsonDictionary = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)

completion(jsonDictionary as? [String : Any])

} catch let error as NSError {
print(“Error processing json data: (error.localizedDescription)”)


print(“HTTP Reponse Code: (httpResponse.statusCode)”)

} else {
print(“Error: (error?.localizedDescription)”)


Full access to source code:

Episode tags: duc tran,, developers academy, REST, REST API, REST API in ios tutorial, ios REST API, how to parse json, parse json in ios, parse json, parse json swift, parse json swift tutorial, parse json in Swift, alamofire, alamofire tutorial, uicollectionview, json ios, ios json parsing, ios json, ios json tutorial, json swift tutorial, swift json tutorial, parse json in ios,swiftyjson, nsurlsession, urlsession, firebase






14 responses to “REST API and JSON in iOS: Build Weather App with REST API and Parse JSON in iOS”

  1. Sebastián Bolaños Avatar

    Having trouble when trying to download the resources…. I enter the info requiered and it wont start downloading….. Need Help

  2. rohit sharma Avatar

    hey…..can u make a tutorial of Json parsing using alamofire

  3. o0HellBounD0o Avatar

    Great video. Keep the good work.

  4. Zach McDermott Avatar

    Great video Duc. Easy to follow and very clear explanations on the how and why of the code. You mentioned at one point in the video you would cover how to access current weather by GPS. Can you provide more information on that? Thanks!

  5. Emmanuel Ogbewe Avatar

    Hey there great tutorial , I have an app with users from firebase and they each have posts now I have all the users in a table view , now when I click on a user in a cell I want a collection view with only the selected user
    posts , how can I do that ? Thanks

  6. Ahmed Hasan Avatar

    press command = for resizing the image LABEL

  7. Earl Alexander Avatar

    sorry for that but i fixed it by completion(jsonDictionary as? [String : Any]) swift wants a _.
    So my code looks like this for encase anyone else gets that problem.
    _completion(jsonDictionary as? [String : Any])

  8. Earl Alexander Avatar

    40 minutes in this video i got a db11 breaking point at App.Delegate.swift/ print(jsonDictionary)

  9. Daniel Wennberg Avatar

    Great work man, keep em coming.

  10. Mn Avatar

    Could you upload a tutorial of how to fix a Angular 4 Firebase Sign Up web

  11. lucho Avatar

    Why do not you use alamofire ? It's less code

  12. Ankush Jain Avatar

    how to convert generic iOS simulator to iPhone 6s simulator

  13. Reem4real Avatar

    I am a big fan of yours and your videos really helped me understand coding and how to build apps, I admire your videos and how you but hard work into uploading videos However today I am going to start the swift challenge and hopefully I will get better in coding.
    thank you Duc tran and keep up your outstanding and hard work. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *