Decodable in swift | JsonDecoder in swift 5 | parse json api swift 5 Hindi

Описание к видео Decodable in swift | JsonDecoder in swift 5 | parse json api swift 5 Hindi

Decodable in swift is a new way of parsing API in swift. Api parsing in swift is one of the most important concepts and with decodable protocol we can parse json api in one line in swift. Decodable protocol can be used with get and post request.

Api parsing in swift has become easy with JsonDecoder class helps you to decode the JSON and map it to a struct or class which inherits from the decodable protocol in swift.

Codable is a typealias and connects both decodable and codable both but rather than using codeable I want to just present decodable here because let’s try to use only those protocols which our class or struct needs and avoid giving them unwanted features which they won’t use.

In my previous api parsing swift tutorial, I used JSONSerialization to parse API, but with the introduction of the decodable protocol in swift, I want to show how easy it is to use decodable and parse the API in swift.

Swift uses the decodable protocol to internally map the JSON response to a struct or class that inherits from the decodable protocol, you can also use the coding keys enum to instruct swift if it needs to do some custom mapping.

Rather than parsing API using the traditional way, I would propose we use the modern way of parsing API in swift using decodable in swift.

If during the interview or machine test you are asked to parse an API, I would suggest using decodable to parse the API as it’s a one-liner code and the best part is you are not using any third-party library.

If you like the work that I am doing then please subscribe to the channel and share it with your friends and iOS group.

You may download the code from the given link mentioned below

Github: https://github.com/codecat15/Youtube-...
Google Drive: https://drive.google.com/open?id=1U_L...

JSON to swift conversion link: https://app.quicktype.io/ (Go to this site, paste your JSON response and select Swift on the right-hand dropdown where it says language)

Music: https://www.bensound.com/

Connect with me on social media

Email: [email protected]
Twitter:   / codecat15  
Facebook:   / code.cat.792  
Github: https://github.com/codecat15

Комментарии

Информация по комментариям в разработке