Search code examples
iosswiftcore-datacloudkit

Can coredata allow certain fields to be shared across users of app?


App allows individual users to enter fields and save on their device

Name of hotel
Location of hotel
Type of Hotel

And some added features like , if they found the hotel service good or bad.

Now my problem are arising as i want certain info like name of hotel and its location become visible to all users who install the app in favorite hotels section

Is there any option in core data that allows me this or i will need to work on cloudkit, and the question is , if i work on cloudkit, does this make coredata not applicable to project any more ?


Solution

  • First, let's clarify the relationship between CoreData and CloudKit since this is important to your question and the answer.

    CoreData is a persistence framework (tool!) that allows you to save data locally on a device. CoreData, is not meant for sharing data. It is meant for a user to save data and comes with all the security designed by Apple for privacy.

    CloudKit is a persistence framework (tool!) that allows you to save data remotely in Apple's cloud. Because it is saved remotely, it has the ability to allow different devices and users to access the data.

    CoreData can be setup with CloudKit automatically in Xcode which allows a user to save data to local on device storage, with automatic backup to the cloud. This allows a user to save data on one device, and if they use the app on another device, the saved data can be accessed.

    However, CoreData when used with CloudKit, at least when you want automated synchronization, implements a special 'zone' that is not shareable prior to iOS14. It's great but really, you will need to have clearly outlined what data there is in the private database, and what you want to share. There are additional considerations and complications that you will need to address in your app, like configuring controls for editing so that you don't have the user try to edit something for which they do not have access.

    Your question sounds like you want only some of the user's stored data to be shared with others. Additionally, that shared data sounds like an aggregation of many users data (like ratings). In this case, it would be best to process that data with some backend procedure and offer it as a separate CloudKit share. The rationale is, you would not want to require a user to download hundreds, thousands, tens of thousands of user reviews and process them every time for every one who wants it.