Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to MAJOR Core Data Issues with iOS 18 and sdk - Data Missing for many users?!
Hi, Thanks for your response. I don't think we do any of the things you are concerned about. Here is some of the code I use to set up the CoreData/Cloudkit stack and have been using this for a few years now. Nothing changed here in at least 12 months (I am not exactly a piker in this realm :) : class CoreDataUtil: NSObject { @objc var pc = NSPersistentCloudKitContainer(name:iphemeris) private lazy var historyRequestQueue = DispatchQueue(label:history) let coreDataLogSubsystem = com.iPhemeris.coreData let coreDataLogger = Logger(subsystem:com.iPhemeris.coreData, category:Cloudkit) @objc var useiCloud:Bool = userSettings.bool(forKey:UseIcloudKey) { didSet { userSettings.set(useiCloud, forKey:UseIcloudKey) if(pc.persistentStoreCoordinator.persistentStores.count > 0) { let store = pc.persistentStoreCoordinator.persistentStores[0] do { try pc.persistentStoreCoordinator.remove(store) } catch { coreDataLogger.log(*** CoreDataUtil toggle use iCLoud ON/OFF FAILED: (error, privacy:.public)) } } self.initCor
Jan ’25
SwiftUI macOS app not syncing with iCloud
I have an iOS and iPadOS app that use iCloud to sync. They are in the App Store and the database was pushed to production. They work as advertised. I wrote also a macOS app that uses Cloudkit, the container it set as NSPersistentCloudKitContainer and the merge policies are set ok. I also checked that the profile for the app and certificates are good to go, as well as the permissions of the app. Apple signed the app, but, it doesn't sync with iCloud and I can't figure out why. I checked iCloud on my Mac and the app is there, set to be syncing. I have already read a few articles and have tried all the possible solutions, including signing out and back in, rebuilding the app, etc. One thing, thought, when I delete an item, the app takes sometime to react to it, as if it's trying to connect. I tried with TCPDump, and other things to check for connection issues, but I can't find that app trying to connect. I took a few screenshots of the different configs, etc so you can see as well, but has anyone run in
2
0
2.1k
Nov ’22
How is Record Zone Sharing done?
My use case is the following: Every user of my app can create as an owner a set of items. These items are private until the owner invites other users to share all of them as participant. The participants can modify the shared items and/or add other items. So, sharing is not done related to individual items, but to all items of an owner. I want to use CoreData & CloudKit to have local copies of private and shared items. To my understanding, CoreData & CloudKit puts all mirrored items in a special zone „com.apple.coredata.cloudkit.zone“. So, this zone should be shared, i.e. all items in it. In the video it is said that NSPersistentCloudKitContainer uses Record Zone Sharing optionally in contrast to hierarchically record sharing using a root record. But how is this done? Maybe I can declare zone „com.apple.coredata.cloudkit.zone“ as a shared zone?
2
0
1k
Jun ’21
Child records not showing in the Shared Database when sharing the Parent record in CloudKit
I've set up a Core Data mirroring to CloudKit using NSPersistentCloudKitContainer. My simplified data structure consists of List and Item. List have one-to-many relationship items with many Items, Item has parentList property. When I am getting CKRecord associated with List NSManagedObject and sharing it, I expect all child Items to be shared too. I know, I can set parentRecord property for each CKRecord associated with the List childRecord.setParent(parentRecord) But I believe there is some smart way to avoid doing that manually, because everything is mirroring automatically and it looks not nice to start handling each single property manually to only set parentRecord. Is there any way to do that for NSManagedObjects? Because my custom relationship does not mean for CloudKit that the List is parent for the Item.
0
0
529
Jul ’20
Field '___modTime' is not marked sortable
I'm using NSPersistentCloudKitContainer and I'm getting warnings in the console saying: CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _scheduleAutomatedExportWithLabel:activity:completionHandler:]_block_invoke(3457): - Finished automatic export - AppActivationExport - with result: storeIdentifier: F2C60E7A-CEC4-44F2-B467-7324C065AD33 success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134406 Request '1FA53D40-43FB-4751-8719-0D26393D5301' was aborted because the mirroring delegate never successfully initialized due to error: UserInfo={NSLocalizedFailureReason=Request '1FA53D40-43FB-4751-8719-0D26393D5301' was aborted because the mirroring delegate never successfully initialized due to error: } I have added indexes for recordName and modifiedTimestamp to all my records as queryable as per the instructions.
2
0
1k
May ’23
What should be the expected user experience from an app that uses CloudKit/Sync
I have a SwiftUI app where I would like to enable NSPersistentCloudKitContainer to start using CloudKit and be able to sync the content of the app between multiple devices, but I'm not sure how to handle the user experience. Should this be a feature that the user turns On and Off in the app settings screen or does the user expects the syncing mechanism to work by default without having to do anything, can someone please share your experience on how you implemented CloudKit/Sync in your app. Do I need to offer a login mechanism so the user logs in? Should I include an On/Off option so the user decides if they want the sync option or not? In general, can someone be so kind and explain what the user experience should be when an app provides ClouldKit/sync? FYI - I'm not asking how to implement CloudKit sync I already know what it is and how it works. I just need to know what the expedition is from an app the provides that feature. Thanks!
1
0
740
Dec ’21
Saving and fetching to Core Data
I am trying to save to Core Data so when the App is reopened the data will be there. I have a single ViewController, within that VC I have 10 Text Fields which the user inputs their data (numbers). I have a function where I add all the data for the 7 days (sun - sat) and it shows the total value. I have most in place (xcdatamodeld)... Is it possible to have CoreData fill text fields? Is there a good tutorial on completing core data? Most I have read and watched all use table views for the example.What I want to do is have the same data show up after closing and re-opening the App. // MARK: - Core Data stack lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: Numbers) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and termina
1
0
830
Feb ’21
swiftUI apps with SwiftData and CloudKit crashes on iOS but works on MacOS
sample code let modelConfiguration = ModelConfiguration() // 1. create mom guard let mom = NSManagedObjectModel.makeManagedObjectModel(for: [Attachment.self]) else { fatalError(====> makeManagedObjectModel error) } // 2. create description with config url and setting let description = NSPersistentStoreDescription(url: modelConfiguration.url); description.shouldAddStoreAsynchronously = false; container = NSPersistentCloudKitContainer(name: swiftDataCloudTest, managedObjectModel: mom); container.persistentStoreDescriptions = [description] // 3. get modelContainer let modelContainer = try! ModelContainer(for: Attachment.self, configurations: self.modelConfiguration) this code works fine on MacOS(14.4.1) and previous iOS 17.x.(iOS 17.2 is OK) but on iOS 17.5, the app crashes with message A Core Data error occurred. UserInfo={NSLocalizedFailureReason=Unable to find a configuration named 'default' in the specified managed object model how can I fix these?
5
0
1.3k
Jun ’24
CloudKit and CoreData synchronization
Hello I am developing an app with SwiftUI using CoreData and iCloudKit to sync data between platforms. The problem is that the iCloud background update is not being triggered when staying in the application. If I make changes on both systems, the changes are being pushed, however not visible on the other device. I need to reload the app, close the app and open again. I already enabled iCloud capability, background notifications and push notifications. This is my persistentContainer var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: Test7) container.loadPersistentStores(completionHandler: {(StoreDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy return container }() func saveContext() { let context = persistentContainer.viewConte
3
0
2.5k
Jun ’21
Sync iCloud with different targets
Hello Is there a way to share data stored in CloudKit and CoreData between iOS and watchOS in SwiftUI? I am using the same CoreData file both, and I am using the same PersistenceController file both, and I am using the same CloudKit container for both. I tried adding the App Groups capability to all the targets, but it is not working. (I already enabled iCloud capability, Push notification capability and background Modes capability for both iOS and WatchOS) PersistenceController: struct PersistenceController { static let shared = PersistenceController() static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext do { try viewContext.save() } catch { let nsError = error as NSError fatalError(Unresolved error (nsError), (nsError.userInfo)) } return result }() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: Test7) if inMemory { container
0
0
645
Jun ’21
Trigger data transfer from watchOS when connectivity is restored
Hello, I have an iOS app and a companion watchOS app. Users record a workout on Apple Watch, the data for which is then transferred using both Watch Connectivity and Core Data + CloudKit (NSPersistentCloudKitContainer) to their iPhone, where it is processed and displayed. As users are recording the workout on their Apple Watch, when they finish and the transfer begins, their iPhone is often not reachable to immediately send the data using Watch Connectivity and they have no network connection (cellular or Wi-Fi). With Watch Connectivity I use transferFile from WCSession, which queues the file for transfer. With Core Data + Cloudkit I save the data and the export is queued. An undetermined amount of time may pass until the user returns to their iPhone or connects to Wi-Fi and most of the time neither of the transfer methods actually transfers the data until the user opens the watchOS app into the foreground, at which point the transfer happens immediately for both methods. I've tried a number of thing
1
0
987
Jun ’24
Prevent data loss from delayed schema deployment
Hi all, I recently discovered that I forgot to deploy my CloudKit schema changes from development to production - an oversight that unfortunately went unnoticed for 2.5 months. As a result, any data created during that time was never synced to iCloud and remains only in the local CoreData store. Once I pushed the schema to production, CloudKit resumed syncing new changes as expected. However, this leaves me with a gap: there's now a significant amount of data that would be lost if users delete or reinstall the app. Before I attempt to implement a manual backup or migration strategy, I was wondering: Does NSPersistentCloudKitContainer keep track of local changes that couldn't be synced doe to the missing schema and automatically reattempt syncing them now that the schema is live? If not, what would be the best approach to ensure this orphaned data gets saved to CloudKit retroactively. Thanks in advance for any guidance or suggestions.
0
0
151
Jun ’25
How to turn On/Off iCloudKitSync on a SwiftUI application
I'm trying to give the user the ability to decide whether they want to sync to CloudKit or not by turning On or Off a Switch located somewhere in the app settings screen but I'm not sure how to do it in SwiftUI. The following code successfully stops the sync to CloudKit by setting the cloud kit container options to nil description.cloudKitContainerOptions = nil. class CoreDataManager{ static let instance = CoreDataManager() let container: NSPersistentCloudKitContainer let context: NSManagedObjectContext init(){ container = NSPersistentCloudKitContainer(name: CoreDataContainer) guard let description = container.persistentStoreDescriptions.first else{ fatalError(###(#function): Failed to retrieve a persistent store description.) } description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) description.cloudKitContainerOptions = nil container.loadPersistentStores { (descri
2
0
1.5k
Dec ’21
Mistake about CKReference in Using Core Data With CloudKit (WWDC 2019)
The presenter says you might be wondering why we don't do this with CKReference instead. And that's because CKReference has some limitations that we don't think work well for Core Data clients. Namely that it's limited to 750 total objects. However, that isn't correct, the 750 limit is only for references that have a delete action: https://developer.apple.com/documentation/cloudkit/ckrecord/reference Important There is a hard limit to the number of references with a CKRecord.ReferenceAction.deleteSelf action that any one record can have. This limit is 750 references, and any attempt to exceed it results in an error from the server. This is why the Notes app has no issue with more than 750 note records with a reference to a folder record. I really wish NSPersistentCloudKitContainer had used CKReference and also that _CKReferenceActionValidate was made public. CKShare has limitations too, yet it used that and there was no custom sharing done like custom references were done.
0
0
851
May ’22
Field recordName is not marked queryable
I'm using NSPersistentCloudKitContainer and in the CloudKit dashboards I have added indexes for all my records modifiedTimestamp queryable, modifiedTimestamp sortable and recordName queryable. But I'm still getting this warning message in the console. error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:](1400): : Import failed with error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](2312): - Attempting recovery from error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _recoverFromError:withZoneIDs:forStore:inMonitor:](2622): - Failed to recover from error: CKErrorDomain:12 Recovery encountered the following error: (null):0 error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate resetAfterError:andKeepContainer:](612): - resetting internal state after error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2200): - Never successfully initialized and cannot execute request ' A3F
2
0
1k
Sep ’24