UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

What is the best way to provide predetermined Core Data data and not overwrite it when user opens app on another device?

Forums > iOS

Please, help me to figure out right way of doing the following:

My goal is to build an app that has fixed number (120, for example) of, let's say, Items. Each Item must have predetermined title (String) and description (String) by me in advance, same for all users. Also Item must have completed (Bool) property and comment (String) property — but they are must be controlled by the user.

Data in all Items must sync via CloudKit on all user devices.

I was thinking of programmatically creating Items in Core Data when user first launches the app, and then only allow editing for completed and comment properties. But I think this may lead to unexpected results, since on the second device user may initiate that process again and data will be replaced with default records, and synced to CloudKit.

Also I was thinking of providing static JSON file with 120 records for Items (with title, description) and then create records in Core Data for only changed Items.

Would appreciate any suggestions, thanks.

3      

My first thought it to add an Entity in the CoreData to save the user preferences and application state. Assuming the "other device" will be using the same copy of the database.

3      

You would want to check if there are any existing records in CloudKit and, if not, create them in Core Data and push to CloudKit. Then when the user launches your app on a different device and the app checks if there are any existing CloudKit records, it will find them and pull them down rather than creating new ones.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.