Discover How To Save Your API Response Into SwiftData ☁️ | SwiftData Tutorial | #7

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ส.ค. 2024
  • ⏭️ Next Video: Saving Images in SwiftData - • How To Store An Image ...
    ⏮️ Previous Video: Prefill JSON In SwiftData - • How To Use JSON To Pre...
    Discover How To Save Your API Response Into SwiftData ☁️ | SwiftData Tutorial
    **********************************
    Timestamps:
    00:00 - Intro
    04:02 - Setting up our SwiftData Model
    07:12 - Fetching our data from SwiftData using @Query
    09:32 - Adding in a cache With SwiftData
    15:21 - Cleaning up our data in SwiftData
    **********************************
    In this SwiftData Tutorial we'll be taking a look at how to save JSON into SwiftData. But specifically using an API. We'll how how SwiftData works with API calls and also how we can use swiftdata and codable to help boost the performence of our apps.
    We'll look at how we can use Swift Concurrency Async Await to make a request to an API and store the response into SwiftData, using swiftdata with codable and also swiftdata with async await. And Learn how you can make your SwiftData models Codable.
    **********************************
    Check Out My Courses 👨🏽‍🏫
    Enjoy my teaching style? Check out my other courses on my website that may interest you, they range from beginner to advanced topics within iOS development.
    Link to Website
    tunds.dev/#courses
    **********************************
    Join the crew 🤝
    Want to help support the channel? Become a member with the join link below and get access to exclusive badges and stickers, as well as other perks that are coming soon.
    Become a channel member
    www.youtube.com/@tundsdev/join
    Support in other ways 💕
    You can support me for free and help the channel grow so that I can continue to make the best iOS development content for you by liking, commenting, subscribing, and hitting the notification bell.
    All of this really helps my channel grow and allows me to keep on making content for you. If you’re interested in subscribing to the channel then you can do so with the link below.
    Subscribe to the tundsdev TH-cam channel
    th-cam.com/users/tundsdev?su...
    **********************************
    Download Source Code
    Interested in looking at the source code? Then check out the GitHub Repo below
    github.com/tunds/youtube-cont...
    **********************************
    EditorKeys
    View Editor Keys Amazing Products with the link below and use the discount code for 10% off any product
    www.editorskeys.com/tundsdev
    Get a 10% Discount Code on any product with the code below
    TUNDSDEV
    See my keyboard cover in action with my review below 👇🏾
    • Increase Your Xcode Pr...
    **********************************
    RØDE Wireless Mic
    amzn.to/3D5qo3V
    RØDE SmartLavPlus Microphone
    amzn.to/3DtVUdG
    2021 Apple MacBook Pro (16-inch, Apple M1 Pro chip with 10‑core CPU and 16‑core GPU, 16GB RAM, 1TB SSD) - Space Grey
    amzn.to/3Drc2fH
    Apple Magic Keyboard with Numeric Keypad (Wireless, Rechargeable)
    amzn.to/3VUctXh
    Apple Magic Mouse
    amzn.to/3sqXSoM
    Secretlab TITAN 2020 Charcoal Blue Gaming Chair
    amzn.to/3D2jVXI
    ErgoFoam Ergonomic Foot Rest for Under Desk
    amzn.to/3srJOLM
    Lumbar Support Pillow
    amzn.to/3eXVfrg
    Macbook Stand for Apple Macbook and All Notebooks
    amzn.to/3DqG7vR
    Portable Chair Green Screen Background
    amzn.to/3gG62GU
    **********************************
    #iosdev #iosdevelopment #swift #swiftlanguage #xcode #appdevelopment #mobileappdevelopment #iosappdevelopment #appdeveloper #iosprogramming #iosengineer #appdevelopmenttips #iosdevelopmenttips #swiftui

ความคิดเห็น • 42

  • @tundsdev
    @tundsdev  11 หลายเดือนก่อน +2

    🚨Xcode Update🚨
    Starting from Xcode 15 Beta 5, when sorting items you now need to include the root in the keypath too, so update the sort parameter to look like this.
    @Query(sort: \Photo.id) private var photos: [Photo]

  • @t.o.n.i.o
    @t.o.n.i.o 9 หลายเดือนก่อน +1

    Great video, thanks a lot!

  • @ConnorH713
    @ConnorH713 5 หลายเดือนก่อน +1

    Love your videos dude! They're super informative and entertaining

    • @tundsdev
      @tundsdev  5 หลายเดือนก่อน

      Glad you like them!

  • @SiamakAshrafi
    @SiamakAshrafi ปีที่แล้ว +1

    Oh ... nice! Thanks for the tutorial

    • @tundsdev
      @tundsdev  ปีที่แล้ว

      Glad you found it useful 👌🏾

  • @chukwumaugonabo1045
    @chukwumaugonabo1045 2 หลายเดือนก่อน

    Great Stuff!

  • @nickpatel1663
    @nickpatel1663 ปีที่แล้ว +1

    thank you tunds for the awesome video! Really enjoyed! I wish to become a top youtube in the iOS community. please keep it up!

    • @tundsdev
      @tundsdev  ปีที่แล้ว

      Glad you enjoyed it 👌🏾

  • @oldschool84
    @oldschool84 8 วันที่ผ่านมา

    You asked us to write in the comments what content we would like to see.
    Well, here is something related to this topic. Can you explain how to fetch and save the data that we would download from an API through the Apollo client. Also, make a tutorial on how to import GraphQL and fetch data through it. Thank you

  • @Lvoonok
    @Lvoonok 3 หลายเดือนก่อน +1

    Maaaaaaannnnn….. Thank you so very much for all your hard work and videos!
    The way you show live use tricks and technics are extremely useful. Love your teaching style (big fan!!!).
    I don’t usually leave comments anywhere. But YOU Sir, are AMAZING.
    Once again, thank you! Please keep making more tutorials, to many it might seem trivial, but YOU ARE CHANGING SOMEONES LIVE 🙏🙏🙏
    P.s. Baki vs Pickles was crazy

    • @tundsdev
      @tundsdev  3 หลายเดือนก่อน +1

      I appreciate that!

  • @kyle-roche
    @kyle-roche 6 หลายเดือนก่อน +1

    Thanks. Like the channel! How are you handling updates back to the server. Example would be delete a record on the phone… where are you sending the delete call back to server?

  • @dimaobertinskiy
    @dimaobertinskiy 11 หลายเดือนก่อน

    Hi. Thanks for your videos. Why did you convert lastFetchedTime interval to a date instead of comparing it to the now time interval ?

    • @tundsdev
      @tundsdev  11 หลายเดือนก่อน +1

      Hi,
      Glad you enjoyed it. The reason why i use a time interval for the appstorage is that appstorage in SwiftUI doesn't support saving a Date yet as far as i'm aware of. So it convert it into a time interval representation. Then back to a date so that i can use the calendar to compare if it's been a certain number of seconds. I wouldn't want to compare two time intervals and it's just clearer for me to visualise too. Hope this answers your question.

  • @kenturnbull9679
    @kenturnbull9679 20 วันที่ผ่านมา

    Try a little Old Bay on your Chip buttie. You don't know what you're missing

  • @mattross9992
    @mattross9992 7 หลายเดือนก่อน

    Hey Tundsdev, It erased my earlier comment lol. Anyway shorter version is I am looking at either doing. this approach or trying to preload it via JSON file or making the data in another app and dropping it in. It is a LOT of dates not sure which way to. go. I got it working so. far but when I tried adding the encoding in manually to make it a swift data class. I am just getting errors.

  • @gmjelle
    @gmjelle 11 หลายเดือนก่อน

    Awsome video! Do you think they'll fix the Codable error by the time xcode gets out of Beta?

    • @tundsdev
      @tundsdev  11 หลายเดือนก่อน

      I actually don’t know if its an error or if it’ll be fixed 😅
      It may be there by design 😬
      Glad you enjoyed the video

  • @thomasfahlke4253
    @thomasfahlke4253 ปีที่แล้ว

    Thanks tunde. Great job.
    But how can I save Images in Swiftdata synced with iCloud?

    • @tundsdev
      @tundsdev  ปีที่แล้ว

      Thanks & saving an image is coming next up 👀 the iCloud stuff, i’ve not decided yet 😅

  • @ChadShryock
    @ChadShryock 10 หลายเดือนก่อน

    Do you have an example with relationships and caching data into SwiftData?

    • @tundsdev
      @tundsdev  10 หลายเดือนก่อน +1

      👋🏾 This is part of a free course here on TH-cam, You could tweak it to use the techniques in this video
      How To Preload Relationships Into SwiftData ModelContainer ⚡️ | SwiftData Tutorial
      th-cam.com/video/DnZKwlOkRrE/w-d-xo.html
      Full Course
      th-cam.com/play/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7.html&si=zVzmrqDz4MnwTLfR

  • @boyonetouch7407
    @boyonetouch7407 ปีที่แล้ว

    You can explain about code in line function clear photo
    _ = try or dosomething
    What’s useful or when need use that syntax

    • @tundsdev
      @tundsdev  ปีที่แล้ว +1

      The underscore is just a placeholder, the function returns a bool but i don’t want to store it in a variable so I use the underscore as a placeholder

    • @boyonetouch7407
      @boyonetouch7407 ปีที่แล้ว

      @@tundsdev thank you

  • @adamcm82
    @adamcm82 10 หลายเดือนก่อน

    Thank you! I’ve watched all your SwiftData videos. Any idea how to share data with other users? There’s zero documentation on that…

    • @tundsdev
      @tundsdev  10 หลายเดือนก่อน

      Hey hope you enjoy them & can you explain on sharing data with an example pls?

    • @adamcm82
      @adamcm82 10 หลายเดือนก่อน +3

      @@tundsdev Yes, we definitely enjoy all your videos! So, CloudKit easily allows us to persist swiftdata and sync it with all our devices. But, what if I’m creating a Reminders App and want to share a list with you, like the actual Apple Reminders App allows? Not a copy, but a live joint list that we can update together.
      CloudKit supports a public, private, and shared database. And what’s the point in persisting data if you can’t share it with anyone :(
      It seems like all of Apple’s native apps allow for this: photostreams, shared notes, shared reminders, shared calendars, shared locations, shared AirTags, shared safari tabs, etc.
      Whether we’re creating a todo list, a recipe app, or even a game, sharing data is pretty essential.
      Thank you!!!!

  • @vanylaskywalker
    @vanylaskywalker 11 หลายเดือนก่อน

    Are you suggesting we should use codable class model instead of codable struct for json decoding of APIs in real projects, or is this done just for simplicity for this video and it's not something recommended in a real project?

    • @tundsdev
      @tundsdev  11 หลายเดือนก่อน

      Hey, i’d start off with codable imo. You could use this in a real project too. The only time i would use a mapper is if your model changes at lot or if your API response it really big i.e. it has a lot of properties then you could use a mapper to keep the model small and only use the properties you need 👌🏾

    • @vanylaskywalker
      @vanylaskywalker 11 หลายเดือนก่อน

      @@tundsdev Did you mean to say "i'd start off with codable class"? I am currently doing mapping in my project and I find it makes it much more complex. Your reasoning makes sense.

    • @tundsdev
      @tundsdev  11 หลายเดือนก่อน

      Yes start off with codable, it’s better to start simple and then scale if you need too into something more complex.

    • @vanylaskywalker
      @vanylaskywalker 11 หลายเดือนก่อน

      @@tundsdev Hi again, I just realized you might have misunderstood my question. My question was more about if we should use "class" (Swiftdata @Model) or "struct" to decode the API response.

    • @tundsdev
      @tundsdev  11 หลายเดือนก่อน

      @vanylaskywalker Hi, you can’t use struct with the model macro you need to use a class. So by default they would be classes

  • @kiohaha
    @kiohaha 7 หลายเดือนก่อน

    have you anything on swift data from api in a swift package lol