Search results for

“NSPersistentCloudKitContainer”

601 results found

Post

Replies

Boosts

Views

Activity

Reply to Invalid Bundle ID for container
I found a solution for my case, so I'm posting to help anyone else with a similar setup. If you're sharing a CloudKit container across multiple apps (using different bundle IDs), apart from specifying the container identifier when initializing the container, you must set NSPersistentCloudKitcontainerOptions on the NSPersistentCloudKit container (this is in the AppDelegate if you selected the Use CloudKit option during project creation) as shown below: let container = NSPersistentCloudKitContainer(name: ModelName) guard let description = container.persistentStoreDescriptions.first else { tt fatalError(No container descriptions available) } description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier:iCloud.com.organization.ContainerName) container.persistentStoreDescriptions = [ description ] In your code, when you access the desired container, you use the same container ID as in the description above: let container = CKContainer(identifier: iCloud.com.organization.C
Nov ’20
NSPersistentCloudKitContainer reverts NSManagedObject subclass to old value
I have an app that uses NSPersistentCloudKitContainer to synchronise data with iCloud. Users reported occasional data loss after which I started debugging my implementation.Part of my app’s implementation is showing a pop-up that displays information and has a confirm button. When the user clicks this button, one or more instances of a custom NSManagedObject subclass gets modified.At the same time, NSPersistentCloudKitContainer triggers a mirror process when the app resigns and becomes active. This happens when the user clicks the above mentioned confirm button. It does this by executing a NSCloudKitMirroringExportRequest and NSCloudKitMirroringImportRequest request.In other words, in my app, data gets modified (explicitly via code) and gets mirrored (implicitly via CloudKit) at the same time, and this is where things go wrong.Essentially this is what happens:1. A property (NSTimeInterval) of an instance of an NSManagedObject subclass gets incremented (e.g. 0 + 1 = 1).2. NSPersistentCloudKitContainer
2
0
1.3k
Oct ’20
Many-to-one relationship can't be unlinked
I am using NSPersistentCloudKitContainer, and have a many-to-one optional relationship, let say many item to one project.This relationship is optional, so I can do this ->item.project = nilwhen the user decided that this item does not belongs to any project.This code is fine in Core Data, and the inverse relationships are updated accordingly.However, once this gets synced to CloudKit, and come back down, the project relationship will be restored. Setting the project to other entities are fine, it just cannot be set to nil.Playing with the CloudKit dashboard, I realized that the schema that is created have a CD_Project as String. If I create a new item without any project, there's no such field, however, once I assign a project to an item, the field is set, and there is no way to unset this field, even from the CloudKit Dashboard. I naively tried to clear out the string in cloudkit dashboard but it crashes my app when the sync happens.Is this a bug that will be fixed? The issue is also posted by an
3
0
1.4k
Oct ’20
Is it possible to rename Entities after using NSPersistentCloudKitContainer in Core Data?
I've tried using renaming Identifier: 1) Automatic / Lightweight migration seems to fail, because CloudKit integration forbids renaming entities. older devices cannot process these records 2) Tried using just NSPersistentContainer, and the lightweight migration still fails with the above message. NSPersistentCloudKitContainer seems to have marked/tainted the persistent store / SQLite so that renaming of entities is not possible at all. Does anyone know if it is possible to rename entities once you start using NSPersistentCloudKitContainer? (heavyweight migration or such?) Has anyone done this before, in a production app or otherwise?
1
0
1k
Oct ’20
How to add CloudKit to iOS with Watch Project (xcode 12/swift ui)
There isn't a signing capability for icloud that is available for either the app or watchos extension targets. My end goal is to have the CoreData CloudKit container that is used by both applications to be in sync and fetch / update the models they modify. Here is what I've done so far: Create iOS with watch app cookie cutter app with xcode 12 Add Remote Notification for Background Modes for both the iOS and watch extension targets. Note I CANNOT find anything to do with icloud or cloudkit as a capability to add. Add the persistence context to the iOS App @main struct MyApp: App { tt@Environment(.scenePhase) private var scenePhase tt@StateObject private var persistentStore = PersistentStore.shared ttvar body: some Scene { ttttWindowGroup { ttttttContentView() tttttttt.environment(.managedObjectContext, persistentStore.context) tttt}.onChange(of: scenePhase) { phase in ttttttswitch phase { ttttttcase .active: ttttttttprint(active) ttttttcase .inactive: ttttttttprint(inactive) ttttttcase .background: ttttttttpr
1
0
1.5k
Oct ’20
CoreData with CloudKit in WidgetKit not working
In my app, I have an NSPersistentCloudKitContainer set up in the following way: let container: NSPersistentCloudKitContainer init() { self.container = NSPersistentCloudKitContainer(name: Model) self.container.persistentStoreDescriptions[0].setOption( true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey } self.container.loadPersistentStores { (_, error) in guard error == nil else { print(error loading store: (error.debugDescription)) return } } self.container.viewContext.automaticallyMergesChangesFromParent = true } When I invoke a fetch request on the context of the container in my iOS target, it works as expected. However, when I perform the same fetch request in my Widget target, it returns an empty array result. In my iOS target, I have Background Modes / Remote Notifications and iCloud / CloudKit capabilities. In my Widget target, I have the iCloud / CloudKit capability. Not sure why it isn't working, so any help would be much appreciated, thanks!
3
0
1.1k
Sep ’20
How to debug NSPersistentCloudKitContainer background updates?
I have been using NSPersistentCloudKitContainer in my app for a while now. My main issue at the moment is that even though I have followed all of the documented steps for setting up background silent notifications, they don't seem to be working. (I query for the Core Data state from a Shortcut/Intent and can verify that the Core Data store hasn't been updated.) This hasn't been too much of an issue, but with new system features like widgets (WidgetKit), this is an issue I can no longer ignore. I'm not sure if it's completely out of my control (e.g. the OS just has decided not to deliver the notifications in the background) or if there's some undocumented step I need to take to ensure it is set up correctly. Has anyone gotten background syncing to work properly with NSPersistentCloudKitContainer? Did you have to do anything special to get it to work? Any tips for debugging what might be going wrong?
5
0
1.4k
Sep ’20
Update an Existing Xcode Project Core Data with CloudKit & Manage Multiple Stores
Hi, I have.a project that uses CoreData and I want to add some of the data to iCloud to sync with a Watch app and I ticked the option for the Default configuration to use iCloud and It worked but now I don't want to include images in the cloud because it became too large so I Seperated the images into a different data thing and as per instructions here https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/setting_up_core_data_with_cloudkit I added a configuration Local and Cloud and change the code as below - original lazy var persistentContainer: NSPersistentContainer = { ttlet container = NSPersistentContainer(name: DataModel) ttcontainer.loadPersistentStores(completionHandler: { ttttstoreDescription, error in ttttif let error = error { ttttttprint(Could load data store: (error)) tttt } tt}) ttprint(Loaded data store: DataModel) ttreturn container }() I created two configurations as per the video and ticked use with iCloud on the one I would like to sync with iCloud. n
1
0
1.6k
Aug ’21
NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
On iOS 13 for transformable attributes that have no custom Transformer class set this appears in the console:One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using NSSecureUnarchiveFromData or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using NSSecureUnarchiveFromData when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.This message appears on devices, in the simulator on High Sierra it even leads to a crash.However, setting the transformer class to NSSecureUnarchiveFromDataTransformer when using CoreData CloudKit, this crashes and leads to Core Data not being initialized.Disabling CloudKit, e.g. setting the .cloudKitContainerOptions on the store description to nil fixes this crash.It seems CoreData CloudKit does not support NSSecureCoding tr
11
0
15k
Sep ’20
iOS 14 WidgetKit + Core Data/CloudKit
I am trying to build a widget for iOS 14 using WidgetKit and CoreData/CloudKit instance on a new Xcode 12 project. I have added my CoreData's File Target Membership to both my app and widget I have added an App Group to my main App Target. My Persistence.swift looks like this: init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: test-cd) let storeURL = URL.storeURL(for: group.test-data, databaseName: test-cd) let storeDescription = NSPersistentStoreDescription(url: storeURL) container.persistentStoreDescriptions = [storeDescription] 4. My widget looks like this: struct Provider: TimelineProvider { var managedObjectContext : NSManagedObjectContext init(context : NSManagedObjectContext) { self.managedObjectContext = context } ... } @main struct test_widget: Widget { let kind: String = test_widget var persistentContainer = PersistenceController.shared.container var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider(context: persistentContainer.v
1
0
2.1k
Sep ’20
NSPersistentCloudKitContainer CoreData & CloudKit Sync Crash
I am using the new iOS 13 NSPersistentCloudKitContainer for Syncing CoreData with iCloud.For large size binary data i am using Allow External Storage in Core Data Model.• I successfully added 200MB sized video on one device.• It got synced to iCloud successfully.• On the other device, when i am opening the App, it is receiving the CloudKit record, but somehow not able to work properly.There is no programming error from my end. I have made sure that in CoreData Model Allow External Storage is selected. Looks like it has something to do with how NSPersistentCloudKitContainer imports the large binary data.Errorerror: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)2020-01-18 20:52:24
2
0
1.9k
Jan ’21
Reply to Invalid Bundle ID for container
I found a solution for my case, so I'm posting to help anyone else with a similar setup. If you're sharing a CloudKit container across multiple apps (using different bundle IDs), apart from specifying the container identifier when initializing the container, you must set NSPersistentCloudKitcontainerOptions on the NSPersistentCloudKit container (this is in the AppDelegate if you selected the Use CloudKit option during project creation) as shown below: let container = NSPersistentCloudKitContainer(name: ModelName) guard let description = container.persistentStoreDescriptions.first else { tt fatalError(No container descriptions available) } description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier:iCloud.com.organization.ContainerName) container.persistentStoreDescriptions = [ description ] In your code, when you access the desired container, you use the same container ID as in the description above: let container = CKContainer(identifier: iCloud.com.organization.C
Replies
Boosts
Views
Activity
Nov ’20
NSPersistentCloudKitContainer reverts NSManagedObject subclass to old value
I have an app that uses NSPersistentCloudKitContainer to synchronise data with iCloud. Users reported occasional data loss after which I started debugging my implementation.Part of my app’s implementation is showing a pop-up that displays information and has a confirm button. When the user clicks this button, one or more instances of a custom NSManagedObject subclass gets modified.At the same time, NSPersistentCloudKitContainer triggers a mirror process when the app resigns and becomes active. This happens when the user clicks the above mentioned confirm button. It does this by executing a NSCloudKitMirroringExportRequest and NSCloudKitMirroringImportRequest request.In other words, in my app, data gets modified (explicitly via code) and gets mirrored (implicitly via CloudKit) at the same time, and this is where things go wrong.Essentially this is what happens:1. A property (NSTimeInterval) of an instance of an NSManagedObject subclass gets incremented (e.g. 0 + 1 = 1).2. NSPersistentCloudKitContainer
Replies
2
Boosts
0
Views
1.3k
Activity
Oct ’20
Many-to-one relationship can't be unlinked
I am using NSPersistentCloudKitContainer, and have a many-to-one optional relationship, let say many item to one project.This relationship is optional, so I can do this ->item.project = nilwhen the user decided that this item does not belongs to any project.This code is fine in Core Data, and the inverse relationships are updated accordingly.However, once this gets synced to CloudKit, and come back down, the project relationship will be restored. Setting the project to other entities are fine, it just cannot be set to nil.Playing with the CloudKit dashboard, I realized that the schema that is created have a CD_Project as String. If I create a new item without any project, there's no such field, however, once I assign a project to an item, the field is set, and there is no way to unset this field, even from the CloudKit Dashboard. I naively tried to clear out the string in cloudkit dashboard but it crashes my app when the sync happens.Is this a bug that will be fixed? The issue is also posted by an
Replies
3
Boosts
0
Views
1.4k
Activity
Oct ’20
Is it possible to rename Entities after using NSPersistentCloudKitContainer in Core Data?
I've tried using renaming Identifier: 1) Automatic / Lightweight migration seems to fail, because CloudKit integration forbids renaming entities. older devices cannot process these records 2) Tried using just NSPersistentContainer, and the lightweight migration still fails with the above message. NSPersistentCloudKitContainer seems to have marked/tainted the persistent store / SQLite so that renaming of entities is not possible at all. Does anyone know if it is possible to rename entities once you start using NSPersistentCloudKitContainer? (heavyweight migration or such?) Has anyone done this before, in a production app or otherwise?
Replies
1
Boosts
0
Views
1k
Activity
Oct ’20
How to add CloudKit to iOS with Watch Project (xcode 12/swift ui)
There isn't a signing capability for icloud that is available for either the app or watchos extension targets. My end goal is to have the CoreData CloudKit container that is used by both applications to be in sync and fetch / update the models they modify. Here is what I've done so far: Create iOS with watch app cookie cutter app with xcode 12 Add Remote Notification for Background Modes for both the iOS and watch extension targets. Note I CANNOT find anything to do with icloud or cloudkit as a capability to add. Add the persistence context to the iOS App @main struct MyApp: App { tt@Environment(.scenePhase) private var scenePhase tt@StateObject private var persistentStore = PersistentStore.shared ttvar body: some Scene { ttttWindowGroup { ttttttContentView() tttttttt.environment(.managedObjectContext, persistentStore.context) tttt}.onChange(of: scenePhase) { phase in ttttttswitch phase { ttttttcase .active: ttttttttprint(active) ttttttcase .inactive: ttttttttprint(inactive) ttttttcase .background: ttttttttpr
Replies
1
Boosts
0
Views
1.5k
Activity
Oct ’20
Reply to Using NSPersistentCloudKitContainer causes crash for iOS 14
My case is exactly like @Michele Longhi's. Except my solution is keeping a singleton of the NSPersistentCloudKitContainer instead of destroying and recreating it multiple times.
Replies
Boosts
Views
Activity
Oct ’20
Display UI when NSPersistentCloudKitContainer begins and ends a sync
Is there any method to receive a notification or callback when NSPersistentCloudKitContainer begins and ends a batch of sync operations? I'd like to be able to show some sort of sync progress in my UI.
Replies
3
Boosts
0
Views
1k
Activity
Oct ’20
Reply to Core Data errors when saving context after syncing from CloudKit
Not explicitly no, am I supposed to? I saw this reply https://developer.apple.com/forums/thread/122745?answerId=382227022#382227022 which mentions that NSPersistentCloudKitContainer does use a custom merge policy (last writer wins) by default which is what I want.
Replies
Boosts
Views
Activity
Oct ’20
CoreData with CloudKit in WidgetKit not working
In my app, I have an NSPersistentCloudKitContainer set up in the following way: let container: NSPersistentCloudKitContainer init() { self.container = NSPersistentCloudKitContainer(name: Model) self.container.persistentStoreDescriptions[0].setOption( true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey } self.container.loadPersistentStores { (_, error) in guard error == nil else { print(error loading store: (error.debugDescription)) return } } self.container.viewContext.automaticallyMergesChangesFromParent = true } When I invoke a fetch request on the context of the container in my iOS target, it works as expected. However, when I perform the same fetch request in my Widget target, it returns an empty array result. In my iOS target, I have Background Modes / Remote Notifications and iCloud / CloudKit capabilities. In my Widget target, I have the iCloud / CloudKit capability. Not sure why it isn't working, so any help would be much appreciated, thanks!
Replies
3
Boosts
0
Views
1.1k
Activity
Sep ’20
How to debug NSPersistentCloudKitContainer background updates?
I have been using NSPersistentCloudKitContainer in my app for a while now. My main issue at the moment is that even though I have followed all of the documented steps for setting up background silent notifications, they don't seem to be working. (I query for the Core Data state from a Shortcut/Intent and can verify that the Core Data store hasn't been updated.) This hasn't been too much of an issue, but with new system features like widgets (WidgetKit), this is an issue I can no longer ignore. I'm not sure if it's completely out of my control (e.g. the OS just has decided not to deliver the notifications in the background) or if there's some undocumented step I need to take to ensure it is set up correctly. Has anyone gotten background syncing to work properly with NSPersistentCloudKitContainer? Did you have to do anything special to get it to work? Any tips for debugging what might be going wrong?
Replies
5
Boosts
0
Views
1.4k
Activity
Sep ’20
Update an Existing Xcode Project Core Data with CloudKit & Manage Multiple Stores
Hi, I have.a project that uses CoreData and I want to add some of the data to iCloud to sync with a Watch app and I ticked the option for the Default configuration to use iCloud and It worked but now I don't want to include images in the cloud because it became too large so I Seperated the images into a different data thing and as per instructions here https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/setting_up_core_data_with_cloudkit I added a configuration Local and Cloud and change the code as below - original lazy var persistentContainer: NSPersistentContainer = { ttlet container = NSPersistentContainer(name: DataModel) ttcontainer.loadPersistentStores(completionHandler: { ttttstoreDescription, error in ttttif let error = error { ttttttprint(Could load data store: (error)) tttt } tt}) ttprint(Loaded data store: DataModel) ttreturn container }() I created two configurations as per the video and ticked use with iCloud on the one I would like to sync with iCloud. n
Replies
1
Boosts
0
Views
1.6k
Activity
Aug ’21
NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
On iOS 13 for transformable attributes that have no custom Transformer class set this appears in the console:One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using NSSecureUnarchiveFromData or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using NSSecureUnarchiveFromData when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.This message appears on devices, in the simulator on High Sierra it even leads to a crash.However, setting the transformer class to NSSecureUnarchiveFromDataTransformer when using CoreData CloudKit, this crashes and leads to Core Data not being initialized.Disabling CloudKit, e.g. setting the .cloudKitContainerOptions on the store description to nil fixes this crash.It seems CoreData CloudKit does not support NSSecureCoding tr
Replies
11
Boosts
0
Views
15k
Activity
Sep ’20
iOS 14 WidgetKit + Core Data/CloudKit
I am trying to build a widget for iOS 14 using WidgetKit and CoreData/CloudKit instance on a new Xcode 12 project. I have added my CoreData's File Target Membership to both my app and widget I have added an App Group to my main App Target. My Persistence.swift looks like this: init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: test-cd) let storeURL = URL.storeURL(for: group.test-data, databaseName: test-cd) let storeDescription = NSPersistentStoreDescription(url: storeURL) container.persistentStoreDescriptions = [storeDescription] 4. My widget looks like this: struct Provider: TimelineProvider { var managedObjectContext : NSManagedObjectContext init(context : NSManagedObjectContext) { self.managedObjectContext = context } ... } @main struct test_widget: Widget { let kind: String = test_widget var persistentContainer = PersistenceController.shared.container var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider(context: persistentContainer.v
Replies
1
Boosts
0
Views
2.1k
Activity
Sep ’20
NSPersistentCloudKitContainer CoreData & CloudKit Sync Crash
I am using the new iOS 13 NSPersistentCloudKitContainer for Syncing CoreData with iCloud.For large size binary data i am using Allow External Storage in Core Data Model.• I successfully added 200MB sized video on one device.• It got synced to iCloud successfully.• On the other device, when i am opening the App, it is receiving the CloudKit record, but somehow not able to work properly.There is no programming error from my end. I have made sure that in CoreData Model Allow External Storage is selected. Looks like it has something to do with how NSPersistentCloudKitContainer imports the large binary data.Errorerror: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)2020-01-18 20:52:24
Replies
2
Boosts
0
Views
1.9k
Activity
Jan ’21
Reply to SwiftUI Xcode 12 Core Data FetchRequest issues
If you Changed the name of your .xcdatamodel file ensure that the same name you changed it to is used when making your container in AppDelegate.swift as below let container = NSPersistentCloudKitContainer(name: Same Name )
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’20