SwiftData & CloudKit: See How To Add Syncing In Your Apps | SwiftData Tutorial | #15

Поділитися
Вставка
  • Опубліковано 30 вер 2024

КОМЕНТАРІ • 43

  • @iLoveAppl3947
    @iLoveAppl3947 4 місяці тому +1

    jeez man... how the heck Apple didn't provide a clear explanations on what to do from A to B in SwiftUI ? how are we supposed to know all of this if for example you didn't make this video ? No wonder people choose Firebase sometimes

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

      Hahaha I got you!

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

    Really great tutorial. Thank-you! I was wondering though... If a user started the app with poor or no internet signal, such that it found none of the restored data in CloudKit, and so then added the data in the app, when the signal was restored, would you end up with duplicates? Perhaps the next launch would remove the duplicates??

  • @Echaront
    @Echaront 2 місяці тому

    Hey @tundsdev! Great tutorial! I'm on Xcode 16 beta and I'm getting a "Extra trailing closure passed in call" error (18:10 of the video) on:
    func fetchItems(
    with query: CKQuery) async throws -> [CKRecord] {
    return try await withCheckedThrowingContinuation{ continuation in
    fetchItems(with: query) { result in
    continuation.resume(with: result)
    }
    }
    }
    I am unable to find any "Async wrapper" options in the Editor menu. Any suggestions?

  • @UltimateGameDeveloper
    @UltimateGameDeveloper 6 місяців тому +3

    great vid really helped but i have a question how would you make the cloud kit only work for your user if he payed for it?

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

      So when you configure your container you can control whether syncing via the ModelConfiguration. So you can set an enum to none, glad it helped too!
      developer.apple.com/documentation/swiftdata/modelconfiguration/init(_:schema:isstoredinmemoryonly:allowssave:groupcontainer:cloudkitdatabase:)

    • @UltimateGameDeveloper
      @UltimateGameDeveloper 5 місяців тому

      @@tundsdevhow would you write it on code tho I understand the logic I just don’t know how to write it in in code

    • @sportguy8135
      @sportguy8135 5 місяців тому

      @@tundsdev I tried what you said but it still syncs

    • @tundsdev
      @tundsdev  5 місяців тому

      Here's a super simple example in a gist, you still need to write your own logic to find out if a user has paid or not using StoreKit2
      gist.github.com/tunds/535a07293766b6fa2d4171ff88625a4d

    • @tundsdev
      @tundsdev  5 місяців тому

      Here's a sample project you could follow to get some ideas
      github.com/tunds/IAPSampleApp/tree/main/IAPSampleApp

  • @kazuya2481
    @kazuya2481 3 місяці тому

    Does Apple support public and shared data from ios18?

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

    Is it possible to download the source code? Thanks.

  • @rafaelplinio6527
    @rafaelplinio6527 7 місяців тому +1

    I have a question: if my app with swiftdata + cloudkit is working fine, with entries and everything.Then I delete it and download it again from the app store. Will it still have the previous data (the entries) since it has cloudkit in it or will it be completed new without any entries?

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

      It should have anything in the cloudkit db, so it should just fetch the model data from the cloudkit dashboard

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

    Thanks for the great video! I’m just starting out so please bear with me. But the code to check for dupes and all seems so complicated, it’s amazing that that’s all necessary.
    Does it prevent content from being downloaded from iCloud to begin with? Checking for duplication before it even downloads it? Or does it just check for duplication after it already downloaded?
    If so, can one not do a check on your model for any duplicate items on app launch / on a timer, and delete those?
    If syncing photos that solution will waste time and bandwidth but if you’re just dealing with small data like text, maybe it’s ok?
    I wish CloudKit / SwiftData just handled this stuff for you to begin with so no boiler plate would be allowed - who wants duplicate data?

    • @tundsdev
      @tundsdev  7 місяців тому +1

      Hey man, like I said in the video this is just something I whipped up on the spot to solve this problem. There’s probs plenty of other alternatives. In your case i dont think you need to do this since i only do it for prefilled data which it sounds like you’re not doing

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

    Have you noticed that if you add an image to a record CloudKit stops pushing updates to the server? Not sure why. I can understand that the image is not pushed up since it is stored locally, but CloudKit stops pushing updates of records without an image as well. Very strange behavior!

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

      Interesting, I've not come across this but I'll keep an eye out on what you've said.

  • @play365alltime
    @play365alltime 7 місяців тому +1

    Awesome tutorial as always. I have a question though, I realise the CloudKit takes a huge time to sync. I mean I want to use that for syncing data between my Watch app and iPhone app, but the CloudKit just doesn't sync for a long time, sometimes I need to wait for several hours. I end up using the transferUserInfo again. (which has size limitation and so complicated) Do you think there are any ways to fix that?

    • @tundsdev
      @tundsdev  7 місяців тому +1

      Glad you enjoyed it, unless you build your own custom sync wrapper. I’ve found it can be hit and miss for when you can get back a successful sync. Sometimes it’s super quick for me though.

  • @holycrosscv
    @holycrosscv 7 місяців тому +1

    Thanks! This is a brilliant CloudKit course and I really appreciate it. There were a couple of catches that always trip me up, and your explanation nailed it! Thanks!

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

      Glad it was helpful!

  • @tvidenov
    @tvidenov 5 місяців тому

    Thanks you @tundsdev for the great explanation. Can you give us a link to the code as well? Is currently missing from the description.

  • @MrBionik6
    @MrBionik6 7 місяців тому +1

    Awesome man, really nice tutorial. I was waiting for this one ❤

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

      Glad you enjoyed it 🤝

  • @javierdejorgesanchez-garni1158
    @javierdejorgesanchez-garni1158 7 місяців тому +1

    Thanks a lot, this is the only place that goes into deep detail about this matter. One question, for TestFlight do you need to deploy it in production mode as well?

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

      Great to hear, you shouldn’t have to no. But there is no harm in doing it just so you don’t forget

    • @javierdejorgesanchez-garni1158
      @javierdejorgesanchez-garni1158 7 місяців тому

      Great. It is because I did and is not sync. Incredible mystery’s of iCloud… 😂 thanks again 👍

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

    Hi, pre-filling data in Development mode seems to work fine, but when switched over to Production, the data pre-fill all over again. Delating on the device AND in iCloud still creates the default data on both items and categories. Any clue why?
    Thanks.
    Blessings,
    --Mark

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

      Hmmm i’ve not come across this, in the examples I tried. As long as I was able to query if the data already existed in cloudkit that prevented me from inserting the data into the modelcontainer.
      Basically you have to make sure you don’t prefill/insert data if the data is already there in the cloud database.

    • @holycrosscv
      @holycrosscv 7 місяців тому +1

      @@tundsdev I sent an app off to the App Store and forgot to deploy it to production before it was approved. Doh! I just sent in a Hot Fix, and now that it is deployed, this may be the issue I am dealing with.
      Thanks!!

    • @holycrosscv
      @holycrosscv 7 місяців тому +1

      Well, due to the weirdness of iCloud, sending in an update to Apple did nothing to stop the defaults from restoring. Interestingly, though, it is not until the last default Category is deleted before they all restore. The fix was simple enough: just set an AppStorage bool and add a toggle if a user wants to restore the defaults.
      Thanks again for a great tutorial. It really helped out!

  • @grin_phi
    @grin_phi 7 місяців тому +1

    You didn't disappoint with this one Tunds! Helped me heaps. Quick Q. Seems like the code to check if data already exists runs every time the app launches? Any reason not to wrap it in userdefaults/@appstroage first run conditional?

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

      Thanks, the problem is it was using userdefaults before. But with cloudkit and swiftdata it will automatically sync and changes that you have in your cloud storage so on every fresh new device if you have prefilled data it will sync and recreate duplicates. So if you have pre filled data you have to handle this manually with icloud I found

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

      Indeed, but once you have checked (on a new device) could we not set a parameter that prevents future checks on that device?

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

      @grin_phi nope, because you wouldn’t know on a new device. That’s the issue the new device has no awareness of the user defaults. Even if you set a flag after the checks you’d still need to try to find the data in cloudkit before you set any flags

    • @grin_phi
      @grin_phi 7 місяців тому +1

      @@tundsdev I think we got crossed wires - each new device must check for cloudkit contents, but on each device, that check (in my case) only needs to be done once, so I suppress it with a local flag. Nevertheless, your video was a huge help!

  • @gavinjerman
    @gavinjerman 7 місяців тому +1

    Great stuff, thanks.

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

      Glad you enjoyed it

  •  7 місяців тому +1

    👍👍👍

    • @tundsdev
      @tundsdev  7 місяців тому +1

      Glad you’re enjoying it