TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Swift Data and CloudKit

Forums > Swift

I'm having a lot of trouble finding resources that show how Swift Data works with CloudKit. I've never worked with Core Data before so I don't really understand what's going on in tutorials that use it with CloudKit.

I'm trying to transition from Firebase to Cloudkit. There are a few of Models/Records I want to be shared between multiple Users. It's a event app that consists of these models: Location, Event, Attendee, and Post. I don't want Locations to be tied to any one User, and I want Event to be owned by more than one User. Post would be owned by a single User, and Attendee would describe accommodations or details about the User's attendance.

I understand general database schemas, I just don't understand how any of this works between CloudKit Containers and Swift Data. If anyone can point me to info that explains it, or give me some insight, I would appreciate it.

3      

I would also like help ( maybe a video by Paul? ) on exactly the same as you wrote.

3      

Disclaimer: Currently, there seem to be some bugs when sharing data between different devices and sometimes it simply doesn't work. So it's difficult to differentiate if you have a bug in your code or it's a bug in SwiftData's data sharing.

This picture is an example on how to set it up: https://twitter.com/FloWritesCode/status/1668287882711412736

If you haven't watched WWDC videos already you should before starting:

Another examples:

https://medium.com/@priya_talreja/swiftdata-in-swiftui-part-1-18919ce2612

https://medium.com/@priya_talreja/swiftdata-in-swiftui-part-2-7a17b06a328a

4      

@Hatsushira after looking over all the documentation, and also Migrating from the Observable Object protocol to the Observable macro I'm even more confused about what Swift Data even means in my context. From what I understand, Swift Data allows data to persist as a sort of cache on the device that updates when changes occur from the user or server. So if I haven't been using Core Data, I assume Firebase has been doing that job in the background.

But now that I want to replace Firebase, I'm at a loss for how Swift Data does whatever Firebase did. And I haven't even gotten to adding Cloudkit yet. I'm already getting mysterious errors in Swift Previews about 'Fatal Error in SchemaProperty.swift' when I try to add a modelContainer to my Content View.

4      

SwiftData fans take note!

SwiftData was just released, and is in beta form. It will take a while before all the dust settles.

26 and 27 June 2023

In the mean time, take a close look at @twoStraw's upcoming event: HackingWithSwift Live 2023!

See -> Hacking WIth Swift Live 2023

The second day of this two day event, @twoStraws will deep dive into SwiftData. You know he's busy trying out all the options and permutations. One can only guess how busy he is poking and prodding the code to develop examples to cover all of SwiftData's internal goodness and can be covered in a single day.

Because this is a live event, you'll most likely be able to field your tricky SwiftData questions directly to the guru himself. But, I'm sure he'll have a full agenda that will answer our questions before they need to be asked.

Buy your tickets now, and help his charity. All ticket sales support his charity.

5      

I look forward to Paul's explanation of Cloudkit integration. In the meantime, here is a video by Alfian explaining how he was able to get it to work. https://www.youtube.com/watch?v=Envpr8UAgYk

4      

I'm in the process of transitioning from Firebase to CloudKit for my event app. There are specific models/records that I want to share among multiple users. For instance, I want the Location model to be independent of any particular user, while the Event model should be owned by multiple users. On the other hand, the post model should be owned by a single user, and the Attendee model should describe details about a user's attendance. dailysportsupdates.com

3      

Did anyone who saw the LiveStream find any working information details on the matters raised? Hopefully the video will come out for HWS+ members soon.

3      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.