iOS Swift Tutorial - Working with the Web - How to parse JSON into model objects with Codable

preview_player
Показать описание
In this Swift tutorial, you will learn how to work with network services and APIs, and how to parse JSON into model objects that can be used in your iOS app.
I will demonstrate how to read basic JSON data and how to write custom Swift model types.

Overview
00:00 Introduction
01:25 Decoding JSON
08:48 Example with JSONPlaceholder API
17:07 Example with cat API
23:44 renaming of properties and CodingKey
27:09 parsing different types with init(from decoder)
31:58 nested JSON data
35:06 fetching more images
39:44 wrap up

Resources:

Books:
Develop in Swift Data Collections, Chapter 2.4

🤩 Learn more

If you liked what you learned and you want to see more, check out one of my courses!
👩🏻‍💻 Combine course

⬇️ Source Code:

#DecodingJSON #JSON #Swift #ParsingJSON #Codable
Рекомендации по теме
Комментарии
Автор

Thank you for doing a wonderful job explaining things like Codeable, CodingKeys and custom decoding via the init().

cometmace
Автор

Hi can you explain how to call two different api in the same app

DeconstructedLearningOfficial
Автор

What a cute cat! Thanks for this video, Karin!

MauricioChavesDias
Автор

Hello, if it's possible, could you make video about pushing the data fron JSON stage to TableView by using UIKit? Tutorial was avesome! My love for it

yaroslavhoncharenko
Автор

Did you you here Api Key for cat api ? and where ? cause in the website written api key is required

shahmirzali_huseynov
Автор

Thank you very much. It was very helpful for me!

Виталий-оъц
Автор

Ich finde es Toll wie du auf die ganzen Themen eingehst, durch deine Videoreihe konnte ich erst richtig verstehen wie man mit Swift umgeht. Genau auf dieses Video habe ich gewartet.

Ich bin gerade dabei an meiner App über die Socket.IO Schnittstelle Live Daten (im JSON Format) an die App zu senden komme seit Tagen nicht weiter, weil mir Swift immer nur Fehler auswirft. Danke :)

CorexoDeu
Автор

Thank you. This was very helpful and well explained.

ovadianyc
Автор

Hello, what does a JSON file mean? I dont understand anything about those computer tools and files. I just found a random fhir.json 2 file on my iphone in my documents. Could this be a spyware or is it just some other document scrypt from my iphone? ( i did not put it on my phone ) thats why i tought it is weird. You would really help me! Thank you in advance

sharence
Автор

Hey thank you for explanations, everything works perfectly besides one last thing: let breeds: [Breed]. Even though I did everything like you, I still get the error 39:31 but with stringValue: "breeds" instead

rankmacro
Автор

You mention part 1 but there is only 1 video in this playlist :|

hackchild
Автор

Your head us bouncing around like crazy, cant watch thus

TommyKarlstedt
Автор

This is really great! I wish I'd seen these first two videos ~6 months ago when I was first learning about working with APIs - really a good explanation of how they work and how you create your model, even a bit more complicated models. 

Maybe this will be brought up in the third video, but for the fake boolean (like hairless, with Int result of 0 or 1), would it be better to decode the JSON as is (with Int), but then assign the true/false value in a separate view model based on the Int result? It seems really messy to try to assign true/false while decoding, especially if you wanted to use a lot of the returned results.

SBSanook