Codable, Decodable, and Encodable in Swift | Continued Learning #21

Поділитися
Вставка
  • Опубліковано 30 вер 2024
  • Codable is one of the most powerful protocols in Swift! We use this to "decode" and "encode" data in our application. This is especially useful for downloading data from the internet, because when we download data it will come as a foreign data type (usually JSON data). We then use Codable to transform (or "decode") the JSON data into a data type that we have in our iOS application. In this video we will first learn how Codable is actually using Decodable and Encodable protocols behind the scenes to transform the data and then we will learn how to implement Codable itself!
    Next video: • Download JSON from API...
    Last video: • How to use escaping cl...
    🤙 WELCOME BACK 🤙
    WEBSITE: www.swiftful-t...
    DISCORD: / discord
    GITHUB: github.com/Swi...
    SAY THANKS: www.buymeacoff...

КОМЕНТАРІ • 95

  • @frederickjavalera558
    @frederickjavalera558 3 роки тому +35

    I'm glad that you took the approach that you did to first build up our "behind the scenes" insight by going through Decodable, then Encodable, and then, finally, Codable. Great teaching approach.

  • @MrTalhakhan01
    @MrTalhakhan01 3 роки тому +8

    Man, awesome awesome awesome video. I can't stress it enough.. you just explained the concept in most deserving way. Thank you
    Please dont stop teaching

  • @coffeeCatPeanutDust
    @coffeeCatPeanutDust 3 роки тому +9

    Awesome video. I'm surprised I've got this far. For what I'm used to, this is already 'next level' but because it's so well taught I don't feel lost.

  • @oliverpark6116
    @oliverpark6116 2 роки тому +5

    I was doing the Swift UI tutorials in Apple Website, but I could not understand the Foundation part, however, this channel let me to understand quick and easy about Codable.

    • @simply6162
      @simply6162 Рік тому

      Yes this guy is god when it comes to how education should be. This sets a new standard for teaching and it’s hard for me to go back to the old teachings

  • @kriendeau67
    @kriendeau67 3 роки тому +10

    Nick you just totally blew me away! I cannot believe codable is so powerful. Eliminating all that code I was like, this isn't going to work, but it does! Thank you for your clear concise
    teaching methods. Ive been following every video since beginner bootcamp and you have taught me so very much!

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +2

      Haha thanks for watching! Yea, Codable is super powerful :)

  • @kjlee7826
    @kjlee7826 2 роки тому +10

    Thank you for your effort and kindness to explain things even under the hood! Now I finally understood the differences among decodable, encodable, and coddle!!!!!

  • @dodilodi1278
    @dodilodi1278 Рік тому +2

    FYI: if you create CodingKeys first, then init(from decoder) and encode() will be automatically written you start typing it.

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому

      You’re right! This was recently added to Swift.. when I made this video we still had to type it all manually 🥵

  • @stefanlindholm3284
    @stefanlindholm3284 2 роки тому +2

    Thank you Nick for another great video!

  • @nikiforzh
    @nikiforzh 6 місяців тому +1

    Daaaaaaaamnn! Bro, the end of this video is sooo unpredictable, I thought it would be so difficult that I would spend a lot of time on it. Now I know how it works inside, and I can use it! You're a genius! Thank u soo much, love this channel

  • @franklemur5518
    @franklemur5518 2 роки тому +1

    So well explained - Thx I have been struggling with Decode protocol. Not no.

  • @30guarino
    @30guarino 3 роки тому +3

    Great job explaining all of this!! At first I was like WTH is going on here ...then I was like OH! I got it now

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому

      Hahaha thanks David. Yea I know we did a lot of extra coding here but otherwise I would have added "Codable" and no one would understand what was actually happening lol

  • @paulraggett7837
    @paulraggett7837 3 роки тому +4

    I really enjoyed the journey in this video. Great work Nick.

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому

      Thanks again Paul. It's incredible how powerful Codable is haha

  • @andrejkling3886
    @andrejkling3886 3 роки тому +2

    Thank you...

  • @pawelpow
    @pawelpow 3 роки тому +5

    Thank you again! You have the best structured and systematic SwiftUI course out there! It’s an honour to be watching these videos!

  • @prashantsinghchauhan944
    @prashantsinghchauhan944 2 роки тому +3

    I have got an internship cuz of your course out here. Lots of appreciation from India. 🔥

  • @KNOWLEDGEINFINITY_YOUTUBE
    @KNOWLEDGEINFINITY_YOUTUBE 2 роки тому +2

    This guy is a legend... WOW, what an explanation!!!

  • @williamwildsmith5162
    @williamwildsmith5162 2 роки тому +1

    I get 56 bytes. I knew I was special.

  • @calvinkim6615
    @calvinkim6615 Рік тому +1

    Thank you very very much. 🙂

  • @mamazur
    @mamazur 2 роки тому +2

    Nick you are legend!

  • @vladimirmoor
    @vladimirmoor 2 роки тому +2

    The puzzle of JSON, Dictionary, Codable, CodingKeys is completed in my head. Great job!

    • @dugrut1325
      @dugrut1325 2 роки тому +2

      It's all there until I go to sleep, an all that code drains out on my pillow, guuuur!

  • @spradohak
    @spradohak 2 роки тому +1

    Brilliant explanation Nick,
    Thank you a lot

  • @geomichelon
    @geomichelon 2 роки тому +1

    great explanation . I m working with ios since 2013 , i came from objective C , and i never seen a good tutorial like yours. Amazing!!! Greetings from Brazil !!! 🙂

  • @1birocks
    @1birocks 3 місяці тому +1

    Man, you're the GOAT Swift Teacher

  • @Максим-ш7х4й
    @Максим-ш7х4й 3 роки тому +4

    Thank you Nick, cool

  • @hawkeye6614
    @hawkeye6614 7 місяців тому

    🎯 Key Takeaways for quick navigation:
    00:34 📚 *Understanding the Codable protocol in Swift involves delving into decoding and encoding data for app usage.*
    01:45 🌐 *Codable facilitates decoding JSON data from the internet into usable app data and encoding app data into JSON for internet transmission.*
    03:08 🛠️ *Swift's Codable protocol automates encoding and decoding processes, simplifying data handling in apps.*
    07:50 📤 *Simulating data download with mock JSON illustrates preparation for real internet data handling in Swift apps.*
    18:56 🔄 *Codable protocol streamlines data conversion tasks, especially useful for managing complex data models in Swift applications.*
    20:39 🔑 *Conforming to `Decodable` allows initializing a model from data, decoding it into the model.*
    22:56 🛠️ *Customizing `CodingKeys` enables mapping between model properties and data keys during decoding.*
    25:17 🧩 *Efficient decoding with `JSONDecoder` simplifies data processing and model initialization.*
    28:18 📤 *Conforming to `Encodable` allows converting a model into JSON data.*
    32:34 🌟 *`Codable` combines `Decodable` and `Encodable`, automating data decoding and encoding processes.*

  • @bestpricesignsprinting3300
    @bestpricesignsprinting3300 2 роки тому +1

    Amazing!!!!

  • @ecptavares
    @ecptavares Рік тому

    Im following along with your code but using a json file I have with over 3.500 records but after testing a series of possibilites my code is not working due to the line ...let dictionary = localData as? [String:Any]. if I put this two lets in a separated ifs the else statement of the second gets executed so I assumed the error is on the second if right.What am I missing?thank you.

  • @BenjaminEggerstedt
    @BenjaminEggerstedt 2 роки тому +1

    Thanks for going through all that happens in the background, it makes the magic so much more enjoyable! I really enjoy your video series, thank you!

  • @peterellison8306
    @peterellison8306 2 роки тому +1

    Another fabulous video. (Coffee coming!). But how do you conform to Codable if you are using a Core Data Entity as your data model (for data persistence purposes)?

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому +3

      Great question... well we use Codable to decode data from a foreign type (often JSON) into some sort of usable Model in our app. When we fetch items from CoreData, they are already Entities, which are Models that the app already understands. In short, we don't need to do any decoding for CoreData Entities. Some developers will still transform Core Data Entities into more universal data types, but you still wouldn't need to encode or decode.

  • @北屯
    @北屯 Місяць тому

    最後神反轉,很謝謝你教了Codable在幕後倒底做了些什麼,你真的很厲害。
    You're a total rockstar in the Chinese Swift community, with tutorials that are totally on point!

  • @cyberguy6100
    @cyberguy6100 2 роки тому

    Heeeeeyyy bro ur legend i want the codes files u write can u give me github link for it
    The bootcamp files u create in xcode 3>

  • @kdtechniquesofficial6153
    @kdtechniquesofficial6153 2 роки тому

    according to spacebar sounds u have a magic keyboard....😜

  • @paulmax9155
    @paulmax9155 Рік тому

    It's bad practice not to catch errors, not to describe them, and not to show alerts or printouts in the console, do the Do-Catch statement is the best approach.

  • @magedmohmed4403
    @magedmohmed4403 Рік тому

    Thank you Nick , your explanation is very useful for us 🥰

  • @NickGo
    @NickGo Рік тому

    Thank you so much for your way of explaining this! What a saver!

  • @giorgimeqvabishvili8210
    @giorgimeqvabishvili8210 Рік тому

    Thanks a lot Nick, you are very handsome

  • @pakaponwiwat2405
    @pakaponwiwat2405 Рік тому

    Thank you very much, Mr. Nick!!

  • @asfandiyar5829
    @asfandiyar5829 Рік тому

    Mind-blowing. Thanks

  • @yasseraltamimi6171
    @yasseraltamimi6171 2 роки тому

    I hate you so much lool, you did all of that at the beginning and I was like, nooo I'm not gonna do all of that for every model, then BOOM!! Just Codable! 😂😂😂😂

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому +1

      😅 Hahaha yea I had to, otherwise you'd have no idea what was really happening under the hood lol

  • @mishapushka708
    @mishapushka708 2 роки тому

    It's cool Codable😊 Thanks!

  • @Jeff-zc6rr
    @Jeff-zc6rr 4 місяці тому

    how do you know an array of data?

  • @kdtechniquesofficial6153
    @kdtechniquesofficial6153 2 роки тому

    You”re very welcome bro....❤️

  • @nevemra5
    @nevemra5 Рік тому

    Oh! Soooo awesome… thank you

  • @dugrut1325
    @dugrut1325 2 роки тому

    that is some crazy Magic!

  • @23mmvideo
    @23mmvideo 6 місяців тому

    Codable is so cool!

  • @kotya7892
    @kotya7892 Рік тому

    The end is amazing! 🤩

  • @aaronz8952
    @aaronz8952 10 місяців тому

    you done a good video!!

  • @LandanDevenecia-p6t
    @LandanDevenecia-p6t Рік тому

    Thank you so much!

  • @mingzhongdai2870
    @mingzhongdai2870 Рік тому

    This is awesome!!

  • @sureshbabu-qp4zr
    @sureshbabu-qp4zr Рік тому

    Really helpful

  • @uzochukwu1556
    @uzochukwu1556 6 місяців тому

    Awesome!

  • @jamesleetrigg
    @jamesleetrigg Рік тому

    I am a lead iOS developer with lots of experience in Swift still, I always find something new and interesting in your videos. Just because I know something doesn’t mean I know, know something. Understanding something is an order of magnitude, better than knowing something. Thanks for your great content.

  • @meimerlin7141
    @meimerlin7141 10 місяців тому

    Thank you so much for spending so much time to explain the basic and root logic within the struct. The important thing is to the beginner developer, like me, who could really write the code confidently after learning your course!!!

  • @AZMerf
    @AZMerf 3 роки тому +1

    Brilliant! Keep going!

  • @pasha7324
    @pasha7324 Рік тому

    This video is gold 🥇

  • @Natena
    @Natena Рік тому

    This is Crazy how you teach Codable in 30 min, while i ve spent weeks to understand it.

  • @PROAHMO
    @PROAHMO 6 місяців тому

    👏

  • @Watashi10
    @Watashi10 Рік тому

    Wow, such a great and clear video on Codable. Nice unexpected twist at the end :)

  • @sattorjabborov2728
    @sattorjabborov2728 Рік тому

    💥💥💥

  • @olepetersen4460
    @olepetersen4460 3 роки тому +1

    You are a true master - thanks again - again!

  • @curt8806
    @curt8806 2 роки тому

    The best channel on UA-cam for SwiftUI

  • @tarun_reddy
    @tarun_reddy 2 роки тому

    Once again Nick is clutch asf

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      Tarun buddy what's up man. Haven't heard from you in a few weeks, glad you're still here 🥳

  • @rajatpandya4930
    @rajatpandya4930 2 роки тому

    Thank you so much for such a easy videos :) :)

  • @Nunny25
    @Nunny25 2 роки тому

    Hi Nick, amazing ...

  • @kdtechniquesofficial6153
    @kdtechniquesofficial6153 2 роки тому

    Thanks for all your effort. ❤️❤️

  • @sols.2525
    @sols.2525 3 роки тому +1

    Incredible!

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому

      Thanks Scott! I know there was a lot of code in this video haha

  • @creativevision9204
    @creativevision9204 Рік тому

    Awesome explaination. One of the must watch videos if you want to learn #Swift

  • @NiggaInTech
    @NiggaInTech 2 роки тому +2

    Brruuhhhhhhhhhhhh 😩🙏🏿

  • @tibettenballs4962
    @tibettenballs4962 2 роки тому

    Who is this jayson you keep talking about? sounds like you have a crush on him/her..

  • @accountforyoutube2280
    @accountforyoutube2280 4 місяці тому

    Thank you so much master Nick 🥷🏻

  • @gucp
    @gucp Рік тому

    I just wanted to say thank you to Nick for making all these contents and making them available to anyone. The concepts are explained clearly and in a easy-to-understand way.

  • @hihiweiping
    @hihiweiping Рік тому +1

    Thank you so much Nick!! 🙏🙏🙏
    I am super appreciated your efforts to make these amazing tutorials which help me a lot. Nice, clear explanation in proper order. 🦸🧙‍♂
    I would definitely recommend this channel to all of my friends who want to learn swiftUI.