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

  Рет қаралды 3,113

tundsdev

tundsdev

Күн бұрын

Пікірлер: 46
@holycrosscv
@holycrosscv 8 ай бұрын
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 8 ай бұрын
Glad it was helpful!
@MrBionik6
@MrBionik6 8 ай бұрын
Awesome man, really nice tutorial. I was waiting for this one ❤
@tundsdev
@tundsdev 8 ай бұрын
Glad you enjoyed it 🤝
@UltimateGameDeveloper
@UltimateGameDeveloper 7 ай бұрын
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 7 ай бұрын
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 7 ай бұрын
@@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 6 ай бұрын
@@tundsdev I tried what you said but it still syncs
@tundsdev
@tundsdev 6 ай бұрын
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 6 ай бұрын
Here's a sample project you could follow to get some ideas github.com/tunds/IAPSampleApp/tree/main/IAPSampleApp
@javierdejorgesanchez-garni1158
@javierdejorgesanchez-garni1158 8 ай бұрын
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 8 ай бұрын
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 8 ай бұрын
Great. It is because I did and is not sync. Incredible mystery’s of iCloud… 😂 thanks again 👍
@nigelhamilton6359
@nigelhamilton6359 2 ай бұрын
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??
@gavinjerman
@gavinjerman 8 ай бұрын
Great stuff, thanks.
@tundsdev
@tundsdev 8 ай бұрын
Glad you enjoyed it
@jutublizard
@jutublizard 18 күн бұрын
Is it better to sync the data using CloudKit or use own storage api /server?
@tvidenov
@tvidenov 7 ай бұрын
Thanks you @tundsdev for the great explanation. Can you give us a link to the code as well? Is currently missing from the description.
@grin_phi
@grin_phi 8 ай бұрын
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 8 ай бұрын
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 8 ай бұрын
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 8 ай бұрын
@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 8 ай бұрын
@@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!
@kazuya2481
@kazuya2481 4 ай бұрын
Does Apple support public and shared data from ios18?
@Echaront
@Echaront 3 ай бұрын
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?
@play365alltime
@play365alltime 8 ай бұрын
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 8 ай бұрын
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.
@rafaelplinio6527
@rafaelplinio6527 8 ай бұрын
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 8 ай бұрын
It should have anything in the cloudkit db, so it should just fetch the model data from the cloudkit dashboard
@edwardsanchez5278
@edwardsanchez5278 8 ай бұрын
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 8 ай бұрын
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
@nigelhamilton6807
@nigelhamilton6807 2 ай бұрын
Is it possible to download the source code? Thanks.
@holycrosscv
@holycrosscv 8 ай бұрын
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 8 ай бұрын
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 8 ай бұрын
@@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 8 ай бұрын
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!
8 ай бұрын
👍👍👍
@tundsdev
@tundsdev 8 ай бұрын
Glad you’re enjoying it
@holycrosscv
@holycrosscv 8 ай бұрын
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 8 ай бұрын
Interesting, I've not come across this but I'll keep an eye out on what you've said.
@xlzhong4956
@xlzhong4956 3 күн бұрын
how to download this code?
@richardwinters4114
@richardwinters4114 21 күн бұрын
If you disable the cloud sync in the Settings for your app, all data on that device is lost.
@Spacer-l3j
@Spacer-l3j 5 ай бұрын
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 5 ай бұрын
Hahaha I got you!
SwiftData Migrations | SwiftData Tutorial | #11
32:24
tundsdev
Рет қаралды 4,6 М.
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 8 МЛН
Yay, My Dad Is a Vending Machine! 🛍️😆 #funny #prank #comedy
00:17
CloudKit - Intro, Pricing, Terms, & Definitions
17:26
Sean Allen
Рет қаралды 23 М.
SwiftData CloudKit Sync - The Complete Guide
1:02:38
azamsharp
Рет қаралды 8 М.
CoreData в Swift. Разработка приложений
47:55
simpleDEV. Swift c нуля до бесконечности
Рет қаралды 9 М.
SwiftUI Drag and Drop with Transferable Custom Object
26:33
Sean Allen
Рет қаралды 23 М.
8. SwiftData   CloudKit
18:20
Stewart Lynch
Рет қаралды 8 М.
Setup CloudKit in SwiftUI project and get user info | Advanced Learning #21
33:02
Intro to Databases (MySQL, CloudKit, Firebase, Core Data, Realm)
20:43