Search results for

“NSPersistentCloudKitContainer”

601 results found

Post

Replies

Boosts

Views

Activity

Reply to Questions About Updating Older Core Data / iCloud App to Core Data / CloudKit
Once I have the path, I plan to do this.lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: “MyAppName”) // Create a store description for a CloudKit-backed local store let cloudStoreLocation = URL(fileURLWithPath: Original or Ubiquity Path) let cloudStoreDescription = NSPersistentStoreDescription(url: cloudStoreLocation) cloudStoreDescription.configuration = Cloud // Set the container options on the cloud store cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions( containerIdentifier: com.my.container) // Update the container's list of store descriptions container.persistentStoreDescriptions = [ cloudStoreDescription, ] // Load store container.loadPersistentStores { storeDescription, error in guard error == nil else { fatalError(Could not load persistent stores. (error!)) } } return container}()
Jun ’19
Reply to PersistenceController and CloudKit
struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: MJ) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group.com.Jad.MJ)?.appendingPathComponent(MJ.sqlite) else { fatalError(Shared file container could not be created.) } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: YOUR containerIdentifier) container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (er
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
Reply to Error: Failed to sync user keys in simulator
Problem 1: NSPersistentCloudKitContainer doesn't seem to work on simulator Solution: Use device, haven't found a way to make it work on the simulator. Problem2 When using CloudKit APIs (not NSPersistentCloudKitContainer) on the simulator I was getting CKError.notAuthenticated even though I had signed into iCloud on the simulator Root cause This happens when 2FA was enabled on the iCloud account but the 2FA code was asked on the simulator Solution Go to https://appleid.apple.com/, select devices on the sidebar Remove simulator (I found 2 simulators, removed both) Reset Xcode simulator Log into iCloud on the simulator Run the app Hopefully that should work.
Aug ’22
NSPersistentCloudkitContainer Memory Leak -> Crash? (iOS 15 beta 4 & 5)
Background I have an established app in the App Store which has been using NSPersistentCloudkitContainer since iOS 13 without any issues. I've been running my app normally on an iOS device running the iOS 15 betas, mainly to see problems arise before my users see them. Ever since iOS 15 (beta 4) my app has failed to sync changes - no matter how small the change. An upload 'starts' but never completes. After a minute or so the app quits to the Home Screen and no useful information can be gleaned from crash reports. Until now I've had no idea what's going on. Possible Bug in the API? I've managed to replicate this behaviour on the simulator and on another device when building my app with Xcode 13 (beta 5) on iOS 15 (beta 5). It appears that NSPersistentCloudkitContainer has a memory leak and keeps ramping up the RAM consumption (and CPU at 100%) until the operating system kills the app. No code of mine is running. I'm not really an expert on these things and I tried to use Instruments to see i
25
0
13k
Aug ’21
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 iCloud Issues
We will need a feedback report with a sysdiagnose to investigate why the server is unhappy with your request. Typically these are configuration issues of some kind. https://developer.apple.com/documentation/technotes/tn3163-understanding-the-synchronization-of-nspersistentcloudkitcontainer#Capture-a-sysdiagnose
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to NSPersistentCloudKitContainer change cloudKitContainerOptions while app is running
I've similar concerns. The contexts from the first container will not be useable (at least in my testing). Short of tearing down the old core data stack, standing up the new one and traversing the view hierarchy to replace all existing managed objects and managed object contexts, there doesn't seem to be a way to toggle sync using NSPersistentCloudKitContainer. Not being able to pause or toggle sync seems to be a real shortcoming with NSPersistentCloudKitContainer. For kicks, I tried just disabling iCloud for the app Settings->AppleID->iCloud->App but that just deleted all the data on the device. I can live with the eventual consistency and not knowing sync progress, but not being able to toggle sync is a show stopper.
Aug ’20
Reply to Not receiving Persistent Store Remote Change Notification.
I think in built constants have to be used for keys so i changed the code to following... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Expenses]; [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { #ifdef DEBUG NSLog(@Unresolved error %@, %@, error, error.userInfo); #endif abort(); } else { #ifdef DEBUG NSLog(@Store successfully initialized); #endif [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentHistoryTrackingKey]; [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentStoreRemoteChangeNotificationPostOptionKey]; } }]; } return _persistentContainer
Aug ’22
Reply to Sync an interactive widget's Core Data store with the main app (and iCloud)
Showing a hint to users inside the widget that they should open the main app in order to sync is hardly a practical solution and destroys not only the user experience, but the very purpose of interactive widgets. If I need to open the app each time I've pressed a button on the widget, it's not very interactive after all. Yeah, your above argument is quite valid, and is why the technote mentions if that is an appropriate user experience. In this case, you might consider using CloudKit framework directly in your widget. That way, you manage the synchronization with your own code, without relying on NSPersistentCloudKitContainer. To read the data that is on the CloudKit server and is maintained by NSPersistentCloudKitContainer, see Reading CloudKit Records for Core Data. The data your widget writes to the CloudKit server using CloudKit APIs, assuming that it follows the rules described in the above article, should be able to synchronize with NSPersistentCloudKitContainer. This is more
Apr ’25
Reply to Questions About Updating Older Core Data / iCloud App to Core Data / CloudKit
Once I have the path, I plan to do this.lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: “MyAppName”) // Create a store description for a CloudKit-backed local store let cloudStoreLocation = URL(fileURLWithPath: Original or Ubiquity Path) let cloudStoreDescription = NSPersistentStoreDescription(url: cloudStoreLocation) cloudStoreDescription.configuration = Cloud // Set the container options on the cloud store cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions( containerIdentifier: com.my.container) // Update the container's list of store descriptions container.persistentStoreDescriptions = [ cloudStoreDescription, ] // Load store container.loadPersistentStores { storeDescription, error in guard error == nil else { fatalError(Could not load persistent stores. (error!)) } } return container}()
Replies
Boosts
Views
Activity
Jun ’19
Reply to PersistenceController and CloudKit
struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: MJ) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group.com.Jad.MJ)?.appendingPathComponent(MJ.sqlite) else { fatalError(Shared file container could not be created.) } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: YOUR containerIdentifier) container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (er
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Error: Failed to sync user keys in simulator
Problem 1: NSPersistentCloudKitContainer doesn't seem to work on simulator Solution: Use device, haven't found a way to make it work on the simulator. Problem2 When using CloudKit APIs (not NSPersistentCloudKitContainer) on the simulator I was getting CKError.notAuthenticated even though I had signed into iCloud on the simulator Root cause This happens when 2FA was enabled on the iCloud account but the 2FA code was asked on the simulator Solution Go to https://appleid.apple.com/, select devices on the sidebar Remove simulator (I found 2 simulators, removed both) Reset Xcode simulator Log into iCloud on the simulator Run the app Hopefully that should work.
Replies
Boosts
Views
Activity
Aug ’22
NSPersistentCloudkitContainer Memory Leak -> Crash? (iOS 15 beta 4 & 5)
Background I have an established app in the App Store which has been using NSPersistentCloudkitContainer since iOS 13 without any issues. I've been running my app normally on an iOS device running the iOS 15 betas, mainly to see problems arise before my users see them. Ever since iOS 15 (beta 4) my app has failed to sync changes - no matter how small the change. An upload 'starts' but never completes. After a minute or so the app quits to the Home Screen and no useful information can be gleaned from crash reports. Until now I've had no idea what's going on. Possible Bug in the API? I've managed to replicate this behaviour on the simulator and on another device when building my app with Xcode 13 (beta 5) on iOS 15 (beta 5). It appears that NSPersistentCloudkitContainer has a memory leak and keeps ramping up the RAM consumption (and CPU at 100%) until the operating system kills the app. No code of mine is running. I'm not really an expert on these things and I tried to use Instruments to see i
Replies
25
Boosts
0
Views
13k
Activity
Aug ’21
Reply to NSPersistentCloudKitContainer not syncing existing data
Update: Filed a feedback report since this seems to be an issue others are encountering as well. (See https://www.andrewcbancroft.com/blog/ios-development/data-persistence/nspersistentcloudkitcontainer-buggy-behavior-list/)
Replies
Boosts
Views
Activity
Jul ’19
Reply to Can a private database entity have a relationship to a public database entity?
I am having same questions in my mind also Peter. I was thinking that Swift Data would also support Public Data. I have not found any resources which support this is possible. I do not have experience with NSPersistentCloudKitContainer. Does this work for you to mix private and public data ?
Replies
Boosts
Views
Activity
May ’24
Reply to SwiftData with shared and private containers
PoC using SwiftData looked great; then client says I need databases shared. I think, this will take less than an hour... I hope some AI will understand roll this back to Core Data and NSPersistentCloudKitContainer.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
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).
Replies
Boosts
Views
Activity
Jun ’20
Reply to iCloud Issues
We will need a feedback report with a sysdiagnose to investigate why the server is unhappy with your request. Typically these are configuration issues of some kind. https://developer.apple.com/documentation/technotes/tn3163-understanding-the-synchronization-of-nspersistentcloudkitcontainer#Capture-a-sysdiagnose
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to (Swift + CloudKit) or (SwiftUi + Core Data + CloudKit)
CoreData is definitely not falling off :-) Use SwiftUI+CoreData and sync with CloudKit, using either NSPersistentCloudKitContainer, an open-source sync engine like CloudCore, or a third-party sync engine like Ensembles.io
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to NSPersistentCloudKitContainer change cloudKitContainerOptions while app is running
I've similar concerns. The contexts from the first container will not be useable (at least in my testing). Short of tearing down the old core data stack, standing up the new one and traversing the view hierarchy to replace all existing managed objects and managed object contexts, there doesn't seem to be a way to toggle sync using NSPersistentCloudKitContainer. Not being able to pause or toggle sync seems to be a real shortcoming with NSPersistentCloudKitContainer. For kicks, I tried just disabling iCloud for the app Settings->AppleID->iCloud->App but that just deleted all the data on the device. I can live with the eventual consistency and not knowing sync progress, but not being able to toggle sync is a show stopper.
Replies
Boosts
Views
Activity
Aug ’20
Reply to Not receiving Persistent Store Remote Change Notification.
I think in built constants have to be used for keys so i changed the code to following... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Expenses]; [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { #ifdef DEBUG NSLog(@Unresolved error %@, %@, error, error.userInfo); #endif abort(); } else { #ifdef DEBUG NSLog(@Store successfully initialized); #endif [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentHistoryTrackingKey]; [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentStoreRemoteChangeNotificationPostOptionKey]; } }]; } return _persistentContainer
Replies
Boosts
Views
Activity
Aug ’22
Reply to How often iCloud will sync with local swiftData?
Other than what @Fat Xu said, the following post and technote may provide more context: SwiftData and CloudKit Development vs. Production Database TN3163: Understanding the synchronization of NSPersistentCloudKitContainer. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Mar ’25
Reply to Ambiguity around the new CloudKit Dashboard
I am unfamilar with NSPersistentCloudKitContainerbut I note that the following references the private database:https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer?language=objcA container that encapsulates the Core Data stack in your app and mirrors select persistent stores to a CloudKit private database.
Replies
Boosts
Views
Activity
Sep ’19
Reply to Sync an interactive widget's Core Data store with the main app (and iCloud)
Showing a hint to users inside the widget that they should open the main app in order to sync is hardly a practical solution and destroys not only the user experience, but the very purpose of interactive widgets. If I need to open the app each time I've pressed a button on the widget, it's not very interactive after all. Yeah, your above argument is quite valid, and is why the technote mentions if that is an appropriate user experience. In this case, you might consider using CloudKit framework directly in your widget. That way, you manage the synchronization with your own code, without relying on NSPersistentCloudKitContainer. To read the data that is on the CloudKit server and is maintained by NSPersistentCloudKitContainer, see Reading CloudKit Records for Core Data. The data your widget writes to the CloudKit server using CloudKit APIs, assuming that it follows the rules described in the above article, should be able to synchronize with NSPersistentCloudKitContainer. This is more
Replies
Boosts
Views
Activity
Apr ’25