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

CoreData and NSPersistentCloudKitContainer (Sharing)

Forums > SwiftUI

@Kdkwn  

I am searching for a good example how you could integrate Sharing between iCloud Users with CoreData and NSPersistentCloudKitContainer in a SwiftUI app. There are some things online, but I don't find them very useful. Maybe someone has implemented sharing in a CoreData App already and can show me some examples.

I just want the option that a user can share its ShoppingList with others.

Hope somebody can help me with that!

2      

hi,

i have tinkered with this and got most of it to work.

start with this Apple document, which gives a link to download Apple's sample sharing project.

the gist is:

  • you'll need to set up your Core Data persistent store into two parts: one for what is your data (you own it, and can choose to share it) and one for shared data (data that is owned by others and shared to you). in the cloud, these stores are mirrored in your .private and .shared databases;
  • you will then invite others to access specific items that you own; and once the invitation is accepted, your data will be made available to them through their .shared cloud database (based on the cloud-mirrored data in your .private database);
  • others will invite you to access items that they own; and once you accept their invitation, their data will be made available to you through your .shared cloud database (based on their cloud-morrored data in their .private database).

in the end, i decided that the notion of distributed ownership was not exactly the type of sharing i really wanted for my app, so i never did finish the last piece, which was to fully implement acceptance of a share in my code.

hope that's a helpful start,

DMG

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.