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

How to toggle iCloud Sync ?

Forums > SwiftUI

I would like to implement a toggle button so people can choose if they want to sync with icloud anytime.

I found https://fluffy.es/toggle-icloud-sync-nspersistentcloudkitcontainer/ , this seems working well, except two problems happen when user switch "not sync" to "sync" in one of device:

  1. In debug windows, it shows:

NSLocalizedFailureReason=CloudKit setup failed because there is another instance of this persistent store actively syncing with CloudKit in this process., NSUnderlyingException=Illegal attempt to register a second handler for activity identifier

  1. the cloud data overwrite the local new data, even I am using NSMergeByPropertyObjectTrumpMergePolicy

if I created only once PersistentCloudContainer in init, and change cloudKitContainerOptions + loadPersistentStores everytime user toggle, there will be error during loadPersistentStores: NSUnderlyingException : Can't add the same store twice

Any tips? Thank you very much!

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.