Populate TableView using URLSession & JSONDecoder in 4 Steps

preview_player
Показать описание


Steps:
1) Analyze & Map JSON to fit your app’s needs
2) Create Structs conforming to Codable protocol
Optional) Add CodingKeys to create readable Structs
3) Call Decoder in URLSession DataTask
4) Populate UI w/ returned data

Рекомендации по теме
Комментарии
Автор

Thanks for this video. It was a tremendous help for me, allowing me to overcome the current problem I was stuck on. I liked and Subbed. Keep up the great content!

datadan
Автор

This is exactly what I was looking for. Thanks!

jmoast
Автор

excellent video, solved one of my problems

mefailtelias
Автор

Nice little example but is has a fatal bug and it crashed on me immediately. You have a single loaded flag for all 9 cells (you set it after 1 cell is loaded). The TableView could request data for any cell in any order. You could have an array of loaded flags but that gets messy. Also you're appending to the array complicates things. What if the table asked for 1, 5, 8 first? But you appended 0, 1, 2. Also the network requests might not finish in the order you requested them. The simplest thing to do is make your array a dictionary keyed by the ID requested. That solves all the issues above. There is no need to have flags at all. Just check if the record is in the dictionary. Like so.

mswlogo
Автор

What is the difference between codable and decodable?

shabba
visit shbcf.ru