Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to I want to make sure to make my app’s data persist across devices, updates, and reinstalls, you need to store it in the cloud.
For data that needs to be accessible across multiple devices (that are logged in with the same Apple ID), even when your app is removed from one of them, consider using cloud storage services, which allow data to be synced across all devices. To use Apple's cloud service, you can look at the following APIs: CloudKit NSPersistentCloudKitContainer NSUbiquitousKeyValueStore iCloud documents This is a lot of things, but it gives you the whole picture about what the platforms have so you can pick the one that fits your use case best. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Oct ’25
Reply to App getting killed by iOS while NSPersistentCloudKitContainer syncs
I'm facing a the same problem. In my case I'm collecting data in background mode. If internet connection gets lost, large amount of data might be sync when the device gets back on the internet. If data collection is still active, the background mode seems to keep NSPersistentCloudKitContainer alive resulting in the iCloud sync not being terminated and the app getting killed due to high CPU pressure. What framework are you using? I'm using SwiftUI. I'm also still looking for a solution.
Aug ’21
Reply to NSPersistentCloudKitContainer data loss edge case
This occurs even if the changes to the managed objects are saved (to the local store) -- it's simply they aren't synced in time. This is by design. Turning off iCloud for an app is equivalent to signing out of the account. Perhaps before NSPersistentCloudKitContainer wipes the local store it ought to force sync with the cloud first? Typically that won't work. By the time an application finds out about an account transition (whether by turning off iCloud for an application or signing out) sync will just fail with CKErrorNotAuthenticated.
2w
Reply to App getting killed by iOS while NSPersistentCloudKitContainer syncs
Have you received any update from Apple on this? They have not replied to my Feedback report at all - not even acknowledged the receipt of my test data, or if it might even be something I’ve done wrong. Nothing. We’re about a month away from release and this is going to break my app if not fixed - which has been working fine for the past 2 years using NSPersistentCloudKitContainer. I suspect there will be a lot of developers & users that will be caught off-guard if it’s released to the public as it’s only a ‘visible’ problem for those of us with slightly complex Core Data models. My app is a medical record keeping app and my users are going to be extremely angry when it fails to sync after they upgrade to iOS15 if this isn’t fixed. In my line of work (I’m an MD) this poor (or no) communication would see me sued by my patients (and quite rightly too) - people just need to know something is being done. Something fundamentally changed with NSPersistentCloudKitContainer from beta 4 and this
Sep ’21
Reply to CloudKit - Conflict Resolution with counters
Operational transforms that model scalar values are typically implemented by collections of contributions (the operations). For example a vector or array of integers that represent the value. The implementations are necessarily aligned with application requirements like language, technology stack, supported distributed systems primitives etc. With NSPersistentCloudKitContainer such a counter is trivially implemented using a one-to-many or many-to-many relationship that joins the transformations to the root entity. If you have specific questions about that we are happy to help, but will require a little more context like your model and desired contribution structure.
Dec ’23
Reply to Widget error upon restore iPhone: The file "Name.sqlite" couldn't be opened
It's interesting huh! One option would be to simply delete the file and let CoreData pull the data from the cloud … you might want to consider just excluding the file from the backup entirely I think this is not an option because the user can turn off iCloud and NSPersistentCloudKitContainer still works to store data without syncing to iCloud. So not all users can get this data back from iCloud, it may only exist in their backup. What does your app actually do and, most importantly, what if any background modes/work does it use? You can think of it as a very simple todo app where you create a todo, it shows up in the widget, and tapping a button marks it complete (via the main app process). Note the widget's access to the database is read-only and cloudKitContainerOptions is not set so the widget extension process does not sync with iCloud (only the main app process does). The only background modes/work used in the app is the remote notifications capability that allows CloudKit to silently notify the
Jun ’25
Reply to CoreData in Swift Packages
Hi, This post helped me so I figured I'd post a working example of the core data model that I am successfully using in a new Swift Package. This code below is from the lazy var persistentContainer: let bundle = Bundle.module let modelURL = bundle.url(forResource: ModelName, withExtension: .momd)! let model = NSManagedObjectModel(contentsOf: modelURL)! let container = NSPersistentCloudKitContainer(name: ModelName, managedObjectModel: model) You can make the model a lazy var. I call it from the host app below: NavigationLink(destination: GenericListCDView() .environment(.managedObjectContext,ModelCDStack.shared.context) , label: { Text(My List) }) Hope this helps.
Jul ’20
Reply to Share an object managed by NSPersistentCloudKitContainer with other users
Hi thank you for making this post. This is really helpful. I have a follow up. There is a 5th point that is missing. What happens when the owner modifies something in the shared document. The other participant can't use private database auto synced with NSPersistentCloudKitContainer because they must use CKContainer.sharedCloudDatabase for shared documents. How to I manually fetch the changes in real time reliability? I saw Maintain a Local Cache For CloudKit Records described here https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users but do not understand it. Could you please describe in simpler steps to keep the CKContainer.sharedCloudDatabase synced in real time. Thank you 🙏
Sep ’20
Reply to NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
I was able to remove the warnings by registering a new value transformer. I'm persisting a CLLocation, which conforms to NSSecureCoding. import Foundation import CoreLocation @objc(CLLocationValueTransformer) final class CLLocationValueTransformer: NSSecureUnarchiveFromDataTransformer { static let name = NSValueTransformerName(rawValue: String(describing: CLLocationValueTransformer.self)) override static var allowedTopLevelClasses: [AnyClass] { return [CLLocation.self] } public static func register() { let transformer = CLLocationValueTransformer() ValueTransformer.setValueTransformer(transformer, forName: name) } } Adding CLLocationValueTransformer as the transformer name works without warnings. The value is synced properly via NSPersistentCloudKitContainer, verified on multiple devices.
Aug ’20
Reply to NSPersistentCloudKitContainer CKRecord conversion errors
@CrunchyBagel Thank you! That is also helpful. I wasn't aware that initializeCloudKitSchema() was different than just manually promoting from development to production after creating test records within the App but I see what you mean now. I thought that NSPersistentCloudKitContainer created all necessary records in the development environment based on whatever is defined inxcdatamodeld as part of how it works and you then later promote those to production. I see it only creates records based on the specific data that has been uploaded which isn't going to include optional _ckAsset records and other things unless those were specifically needed for the test data. Again, much appreciated!
Jul ’23
Reply to CloudKit + Core Data General Questions (HIG)?
Oh cool, I guess cmd+s is post....2) I'm curious if there's a means to allow the user to choose the version of the data in CloudKit or the version of the data on Device. My data sort of adds up to an expected whole. If one record is added or deleted, then the sum of the records will be incorrect. To give the user a good experience, I'd like to give them the ability to pick a snapshot of two different versions of their entire data set.Can `NSPersistentCloudKitContainer` facilitate this in anyway?3) Is there a best practices guide or design pattern recommendations with recards to UX anywhere?
Feb ’20
Reply to Cloudkit and CoreData Sync memory issue with image Data.
I have exactly the same problem, I use NSPersistentCloudKitContainer with Catalyst. The problem started after I deployed the Schema to production.The synchronization works perfectly on all devices (mac, iPhone, Simulator) until I add a photo from Simulator. This photo is synchronized with Mac, but as soon as it tries to sync with iPhone, it crashes. The only way I found not to crash, is to delete as many photos as I had added from Simulator. After that, iPhone crashes stops and starts syncing again.EDIT:I've found that the problem is not from the simulator but from a big image.I tried that using a 8k image and it crashed.If I deselect the Allow External Storage option though, it works fine.
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’20
Reply to Persistent Storage for Previewing
I was able to fix this by moving my data store into its own class and using the same thing for both the app and previews: import CloudKit import CoreData import Foundation class DataStore { static let shared = DataStore() lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: Structure) container.loadPersistentStores(completionHandler: { _, error in if let error = error { fatalError(Unresolved error (error)) } let context = container.viewContext context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy context.automaticallyMergesChangesFromParent = true // other setup here }) return container }() func saveContext() { let context = persistentContainer.viewContext if context.hasChanges { do { try context.save() } catch { fatalError(Unresolved error (error)) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’20
Reply to NSPersistentCloudKitContainer losing data
1. Are you suggesting that iCloud-sync should be enabled by default and if the users want to turn it off then they can do that from System Settings app? Yeah, that will be my choice. 2. Based on your answer, I think I agree that having toggle to enable/disable iCloud will not provide consistent experience. But then I don't understand how that can be fixed since iCloud is available only to the premium users in the app. The toggle is off and disabled for the free users of the app. I didn't think that you'd build your business model based on that. Thanks for bringing this up. I haven't thought from the business model perspective, but one idea is to consider creating a local store and a CloudKit store to manage the data separately. When users choose to opt in, you move the data from local store to the CloudKit one, and let NSPersistentCloudKitContainer take care the rest. By using a local store, you control when to move what data to the CloudKit store. For details about managing multiple stores with one
Sep ’24
Reply to preload core data from cloud kit
This what I use in my apps (during the initialisation of my Data Controller): self.mainContainer = { let container = NSPersistentCloudKitContainer(name: MyDataModel) container.loadPersistentStores(completionHandler: { description, error in if let error = error { print(**** ERROR loading persistent store (error)) } //Setup auto merge of Cloudkit data container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy //Set the Query generation to .current. for dynamically updating views from Cloudkit try? container.viewContext.setQueryGenerationFrom(.current) }) return container }() The key lines are the 2 below //Setup auto merge. Also, be sure to have enabled Remote Notifications in Background modes of the App's Signing and Capabilities. I hope this helps. Regards, Michaela
Apr ’23