Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to Sharing Core Data with watch app in SwiftUI
If you are trying to use an App Group container to share a database between your iOS app and an WatchKit extension, that won't work because the iOS app runs on iPhone and the WatchKit extension runs on the paired watch, and an app ground container can't be cross devices. You will have to synchronize the data across the devices with your own code. As Nick points out, you can try with NSPersistentCloudKitContainer, you can also use CloudKit directly to synchronize the data you need. WatchConnectivity is not recommended if you want your watch app to be standalone.
Jun ’20
NSPersistentCloudKitContainer: Migrating multiple devices with data changes in between
What is the expected / best strategy to migrate a synced Core Data model to a new version? The issue: A new app version with a new Core Data model introducing new attributes or entities. DeviceA installs the update and edits data with new values and creates new entities. DeviceB is still used and downloads these changes. The unknown attributes and entities are ignored, but the HistoryTracking gets updated. A few days later DeviceB gets the update. The missing attributes and entities are not downloaded, as the history is up to date. __ The issue exists with iOS 13, I hoped for iOS 14 to introduce a strategy. I tried with the first iOS 14 beta, but it is at least not handled automatically. From the visible API changes I don't see a way to handle this specifically. Not sure if the talks will reveal anything about it. Will apply for a lab session and would like to get as much input to prepare before that might take place.
9
0
2k
Jun ’20
NSPersistentCloudKitContainer: Migration failed based on alphabetical order
I added a new Core Data model version, introducing a new entity. Based on the naming of the Entity I get different behaviour: A: If the entity is alphabetically ordered as last entity: Everything works fine. B: There entity is ordered before already existing entities: All records of these existing entities get a new CloudKit id. Resulting in duplicated data and broken relations. In some cases the seem-to-be new insert of these records causes the migration to fail. (Constraint unique violation, reason=constraint violation during attempted migration) My only workaround so far is to just give the entity a different name, to appear last in the list. __ Does anyone else experience this issues? I am not sure if my code could be able to trigger this kind of behaviour. I will try to reproduce it in an empty project, to file a bug report.
4
0
1k
Jun ’20
Reply to Core Data and SwiftUI in Xcode 12
You need to create a custom Core Data class and inject it into ContentView() I don‘t have a default file at hand but you can inject it like below let context = PersistentCloudKitContainer.persistentContainer.viewContext tt ContentView().environment(.managedObjectContext, context) Below my CloudKitContainer but you can simply change that to a regular PersistentContainer class import CoreData public class PersistentCloudKitContainer { tt tt// MARK: - Define Constants / Variables ttpublic static var context: NSManagedObjectContext { ttttreturn persistentContainer.viewContext tt} tt tt// MARK: - Initializer ttprivate init() {} tt tt// MARK: - Core Data stack ttpublic static var persistentContainer: NSPersistentCloudKitContainer = { tt ttttlet container = NSPersistentCloudKitContainer(name: Container_Name) ttttcontainer.loadPersistentStores(completionHandler: { (storeDescription, error) in ttttttif let error = error as NSError? { ttttttt ttttttttfatalError(Unresolved error (error), (error.userInf
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’20
Reply to NSPersistentCloudKitContainer not syncing data on macOS
You can use the feedback assistant to file bugs against NSPersistentCloudKitContainer. Include the following: A sysdiagnose from all of the participating devices The persistent store files from all of the participating devices If your dataset is large, a detailed accounting of the affected records and the mutations made to them from each device (as well as you recall, history tracking is the truth)
Jun ’20
Reply to CloudKit + CoreData: Now how do I take advantage of CloudKit user-to-user sharing without losing CoreData + CloudKit synchronization?
You can use NSPersistentCloudKitContainer, but you have to implement the code for sharing manually. Here's a great description of what's needed along with sample code: https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users You can retrieve CKRecord objects from NSPersistentCloudKitContainer using https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3141668-recordformanagedobjectid?language=objc
Jun ’20
Reply to NSPersistentCloudKitContainer and CloudKit for Sharing
Yes, NSPersistentCloudKitContainer doesn't support sharing, you have to implemented that code manually. Here's a great walkthrough along with some sample code: https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users You can obtain an NSManagedObject's underlying CKRecord using https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3141668-record Basically, you need to create a CKShare for each record you'd like to share. Don't forget to setup a CKDatabaseSubscription to get notified about changes. After changing the record, receivers of the share need to store it back to the shared database (and not to their private database, unless they're the owner of the record).
Jun ’20
Reply to Check Data Re-Sync on App Reinstall with CloudKit (+SwiftUI)
I'm using an almost identical CoreData stack as to what was shown in the WWDC 2019 Posts demo app. Here's the code: import Foundation import CoreData // MARK: - Core Data Stack /** The main Core Data stack setup including history processing./ class CoreDataStack { tt/** ttttA persistent container that can load cloud-backed and non-cloud stores. tt */ ttlazy var persistentContainer: NSPersistentCloudKitContainer = { tttt tttt// Create a container that can load CloudKit-based stores ttttlet container = NSPersistentCloudKitContainer(name: MyCoreDataApp) tttt tttt// Enable history tracking and remote notifications ttttguard let description = container.persistentStoreDescriptions.first else { ttttttfatalError(###(#function): Failed to retrieve a persistent store description.) tttt} ttttdescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) ttttdescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) tttt ttttcontainer.loadPer
Jun ’20
Persisting a PKDrawing to iCloud
I have an App in which I am using NSPersistentCloudKitContainer to store user's drawings, and to have them in sync across multiple devices. To store the drawings, I am using a Binary Data attribute in my Core Data entity. In this attribute I am saving the data representation of the drawing by using this API https://developer.apple.com/documentation/pencilkit/pkdrawing/3281878-datarepresentation I have observed that for some drawings this data representation consumes a huge amount of data, and that generates synchronisation problems among devices. Is there a better approach to persist PKDrawings without this problem?
2
0
1.2k
Jun ’20