Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to WidgetKit and CoreData/CloudKit
Short Answer: You can't achieve Core Data / iCloud sync with NSPersistentCloudKitContainer in Widgets I ran many tests with and without WidgetKit and I discovered that no matter what I tried, I could never get NSPersistentCloudKitContainer to sync while an app is in the background. There is no amount of time that you can wait either, the sync will simply not happen. I tried querying Core Data during BackgroundTasks and the data is simply never there. I can see that a sync operation gets queued with a priority of 2 but only when an app becomes active does the sync even run. Widgets always run in the background. Since NSPersistentCloudKitContainer only runs while an app is in the foreground and since widgets only run in the background, the sync will never happen unless you launch the app. This isn't ideal because say you have the app installed on another device like a watch, your widget on your phone will never receive the updates that you do on the watch. At least, not with NSPersistentCloudKitContainer
Nov ’20
iCloud Sync NSPersistentCloudKitContainer: Make use of BGProcessingTaskRequest to catch up?
Hi, I have implemented iCloud Sync using NSPersistentCloudKitContainer. However, I have a lot of data to sync in my use case which can take quite some time (minutes) especially when starting with a new device (10's of minutes). I was wondering if there is a way to make good use of BGProcessingTaskRequest (ie long running task over night, potentially with requiresExternalPower). The idea is to let the device catch up with the remote store during such a long running background task over night/during charge. I already tried to hack my way into this by trying to just listen to sync events during the task and not finish the task until sync events have stopped but it seems the sync processor does have its own awareness of the app moving to the background and therefore might not even wake up during the background task. Any idea how I can help the CloudKitContainer to catch up in the background with very large workloads? Thanks!
0
0
621
May ’22
Core Data + CloudKit > how to incorporate existing app data into new NSPersistentCloudKitContainer
My experience implementing Core Data + CloudKit has frankly been relatively easy and I feel very positive about the new NSPersistentCloudKitContainer.Introduction and ThanksHonestly, I approached the new implementation of Core Data + CloudKit with some trepidation.My fears and anxiety were unfounded and I quickly learned just how (unsettlingly) easy it is to implement a CloudKit backed persistent store using NSPersistentCloudKitContainer.The new Core Data documentation is the best I've read by Apple for many years, so a huge and sincere thank you to the Core Data team.A couple of good posts on SO and a good blog by Andrew Bancroft helped close out my preliminary education... https://www.andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/The sample app provided by Apple (per WWDC session 202: Using Core Data with CloudKit) is madness for a beginner, however I really appreciate the effort that has gone into demonstrating SO MANY capabilities of
Topic: UI Frameworks SubTopic: UIKit Tags:
4
0
2.1k
Oct ’19
Reply to NSPersistentCloudKitContainer - Import failed because applying the accumulated changes hit an unhandled exception
Update for anyone else with this issue. Here is the reply I have received from Framework engineers in response to bug report We have additional information, the root cause of this issue is a large number of incoming images in the same import. You can work around this by syncing your images with CloudKit directly via a CKRecord you own (instead of letting NSPersistentCloudKitContainer do it). We will continue to improve the performance of NSPersistentCloudKitContainer and followup again in this feedback report when the issue is resolved.
Mar ’22
NSPersistentCloudKitContainer - how to reset CoreData+CloudKit after failed automatic migration (while still in development environment)
I have expanded my CoreData model quite a few times, including renaming entities, properties (and as far as I remember relationships). I am still working in the (CloudKit) development environment, only. Now I am getting errors each time I start the app (one line out of many shown): CoreData: debug: CoreData+CloudKit: -PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:(404): Skipping migration for 'ANSCKDATABASEMETADATA' because it already has a column named 'ZLASTFETCHDATE' The app is working as expected, it seems this error has no effect on correct CoreData+CloudKit execution. But I want to get rid of this error warning before I deploy to production for TestFlight or expand CoreData further. To have a clean CD+CK base I can start migrations from in future. Can I just reset CD (or CoreData's model) to make CD accept the current model as the base model without any migrations attached to it? An Apple Engineer suggested here - https://developer.apple.com/forums/thread/47637?answerId=146
3
0
2.9k
Apr ’21
How to deduplicate entities with relationships in NSPersistentCloudKitContainer?
In my app I have a defaultJournal: Journal, that automatically gets added on the user's device on launch. There should only be one default journal, and I know that deduplication as shown in the Apple Demo, is the correct approach to ensure this on multiple devices. Journal looks something like: class Journal: NSManagedObject { @NSManaged var isDefaultJournal: Bool @NSManaged var entries: Set? } Since Journal has a relationship to entries, how can I deduplicate it ensuring that I don't orphan or delete the entries? I am worried that the entries aren't guaranteed to be synced, when we discover a duplicate journal in processPersistentHistory. This would lead to either orphaned or deleted entries depending on the deletion rule. How can one handle deduplicating entities with relationships? For example here is my remove function: func remove(duplicateDefaultCalendarNotes: [Journal], winner: Journal, on context: NSManagedObjectContext) { duplicateDefaultCalendarNotes.forEach { journal in defer { context.delete(journ
1
0
1.2k
Oct ’21
Reply to SwiftData data duplication
SwiftData + CloudKit is currently based on NSPersistentCloudKitContainer. Duplicate data can be generated if you have multiple app instances uploading a same piece of data, as discussed in Remove duplicate data. NSPersistentCloudKitContainer doesn't support unique constraints as of today, and so you will need to remove duplicate data with your own algorithm and code. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
NSPersistentCloudKitContainer sharing with the new databaseScope option
I'm really excited about the new public database options introduced in the Sync a Core Data store with the CloudKit public database talk! I see in the documentation that the databaseScope refers to the CKDatabase.Scope which includes an option for the shared database. Does this mean that we will be able to automatically sync CoreData records to a shared CloudKit database this year? I would really like to add support to my app to sync data with friends through CloudKit, but with the existing system it is too much work to sync shared objects through a CKShare, so I have avoided building it so far. I'm really excited to start using the new changes. Thanks!
5
0
1.7k
Jun ’20
Reply to CloudKit - moving record objects between zones
If you are using SwiftData + CloudKit, which is based on NSPersistentCloudKitContainer, it doesn't support cross-share relationships, and so you can't have a collection in one zone and a relationship of the collection (a sub-collection, for example) in another. This is mentioned in here: NSPersistentCloudKitContainer doesn’t support cross-share relationships. That is, it doesn’t allow relating objects associated with different shares. When sharing an object, NSPersistentCloudKitContainer moves the entire object graph, which includes the object and all its relationships, to the share’s record zone. If you are using the CloudKit framework directly, the source and target objects of CKRecord.Reference must be in the same zone of the same database, and so you will need to maintain the relationship with your own logic. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: Community SubTopic: Apple Developers Tags:
Nov ’25
NSPersistentCloudKitContainer with public database doesn't work and is poorly documented
So I tried the public database feature of NSPersistentCloudKitContainer last year but never really got anywhere so I thought i'd try it again this year. However I've still had basically no luck and I figured now might be a good time to try and document the issues I have had. The documentation for this at https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit mentions shouldInitializeSchema which from what I can gather was removed in a beta version a long ** time ago. It appears to now be a method on the container - container.initializeCloudKitSchema(). Ya'll should update this documentation. initializeCloudKitSchema does not work if you have options.databaseScope = .public on the NSPersistentCloudKitContainerOptions. You get a bunch of errors saying No authToken received for asset Turning off the public scope and then calling initializeCloudKitSchema gets you the Record types you need created in the CloudKit console, then r
9
0
6.2k
Jun ’21