Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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 ’19
cannot push coredata records to cloudkit
coredata pushed schema to cloudkit only for those entities for which I created records. But the record data did not get pushed. I set recordName as Queryable and modifiedTimestamp as both Queryable and sortable. Query does not show the records. I look at Xcode console gives this output for one of the entities that got pushed to cloudkit : CoreData: debug: CoreData+CloudKit: -[PFCloudKitSerializer newCKRecordsFromObject:fullyMaterializeRecords:includeRelationships:error:](575): Serializer has finished creating record: , Also schema for some other entities that do not have any core data records did not get pushed to CloudKit. I thought the entire coredata schema should get pushed along with the records. Looks like it is pushing those entities that have some records but without pushing data. I reset the cloudkit environment and tried again, but issue is not resolved. Also the AppDelegate never gets called. I thought the line below should have called AppDelegate @UIApplicationDelegateAdaptor(AppDelegate.self) var
2
0
1.2k
Aug ’23
Core Data Sharing with iCloud Drive Files
I have an app for client management that stores data in Core Data with an NSPersistentCloudKitContainer. Each manager have their clients in the Core Data Private Database, and each client could have associated files (images, documents, etc) that are stored in app's own folder structure in iCloud Drive. Eventually, a manager can decide if to share a client with another manager, in order to have a shared managed client (readable, or writable+readable by others managers which share the same client). This is done by moving the Client from the Private Database to the Shared Database following the Apple's guidelines: https://developer.apple.com/videos/play/wwdc2021/10015/ This is the structure: The problem is: the database record is shared correctly, but the iCloud Drive Files are not shared (obviously). My goal is to get working the iCloud Drive Client Files (every client has a single Folder) with the minimum effort from the user. I cannot get working the iCloud Drive Sharing from my app, only the Core Da
0
0
902
Oct ’21
Core Data errors when saving context after syncing from CloudKit
In my new SwiftUI app I am using NSPersistentCloudKitContainer API to persist my data and also share it between multiple different devices. I am always using viewContext to fetch or save records, also my Stack consists of two custom configurations where CloudKit is enabled. One for entities to be stored in the CK public database and one for records in the private database. This usually works just fine. I can save or delete records on one device and they appear on the other device. However in some situations, usually after I imported data on device A and use the same device to create a new record I get errors like this when saving context: Error Domain=NSCocoaErrorDomain Code=133020 Could not merge changes. UserInfo={conflictList=( NSMergeConflict (0x28126df40) for NSManagedObject (0x28242eda0) with objectID '0xb76a5d0f17dd5aa9 ' with oldVersion = 33 and newVersion = 34 and old object snapshot = {n id = D1E2B253-723C-406C-8566-2307DA2D5C17;n name = bench;n} and new cached row = {n id = D1E2B253-723C-4
3
0
1.9k
Sep ’20
How to enable/disable cloudkit in runtime.
I am trying to implement toggling iCloud sync in runtime for my App, i.e. when users toggle the switch in my app, a persistent container will be created according to sync on or off. it works when relaunching the app after changing the container, but how to do it in runtime? how to reload data from the new container and refresh into UIs which already contain the old data from the previous container? I searched all over the internet but could not find a solution to toggle iCloud sync in runtime properly. Below is the code from my core data stack: lazy var persistentContainer: NSPersistentContainer = { setupPersistentContainer() }() private func setupPersistentContainer() -> NSPersistentContainer { let isSyncOn = UserDefaults.standard.bool(forKey: isSyncOn) let container = isSyncOn ? NSPersistentCloudKitContainer(name: BaseTypes) : NSPersistentContainer(name: BaseTypes) guard let description = container.persistentStoreDescriptions.first else { fatalError(###(#function): Failed to retrieve a persisten
0
0
1.1k
Oct ’22
SwiftUI TextField present integer (Int64) for macOS target
NumberFormatter does not function as expected under Xcode 13 betas or macOS 12 betas (currently up to beta 5 for both). I've logged feedback to Apple FB9423179. I'm writing a SwiftUI universal app with macOS and iOS targets using Core Data and NSPersistentCloudKitContainer. A Core Data Entity is an Observed Object in the code for a detail View. e.g. @ObservedObject var account: Account where Account is the class. NumberFormatter currently does not function in a TextField on macOS 12, so as a workaround I am currently using with great success: TextField(Sort Order, text: Binding( get: { String(account.sortOrder) }, set: { account.sortOrder = Int64($0.filter{0123456789.contains($0)})! } ) ) where sortOrder an entity attribute of type Optional. This works well for number entry and in my humble opinion is elegant in that it is immediately obvious what the TextField is expected to do to get the information it displays and set the information provided by the user. The only issue is that when the user makes
5
0
2.0k
Aug ’21
How to "Keep on My iPhone" after disabling iCloud for my app using Core Data
I have Core Data setup with a NSPersistentCloudKitContainer as my container, I've added a container identifier and I see my data on CloudKit's database here when I use Act As iCloud Account. Here's what I have under capabilities in Xcode However, on my device when I go to Settings > Apple Account > iCloud > Saved to iCloud and switch off my app, all the data saved to Core Data is removed. I suspected this working as intended. When I switch it back on, all the data comes back. However (x2), the support page here says it should remain on the device: When you turn it off, the app no longer connects with iCloud, so your data exists only on your device Am I missing something in how I integrated Core Data in Xcode? Do I need to explicitly configure something with Apple's SDK to get the behavior described in the support page? I've noticed for some of Apple's apps, when you switch off iCloud there's an action sheet asking what you'd like to do with the local data. I figured this was Apple's magic wi
1
0
1k
Oct ’24
MacOS App Core Data app is stuck in "This NSPersistentStoreCoordinator has no persistent stores (schema mismatch or migration failure). It cannot perform a save operation."
I work on a MacOS app (which has a companion iOS app) that uses Core Data with NSPersistentCloudKitContainer. The app also supports widgets and hence there is a need to migrate the persistent store within the core data stack using replacePersistentStore( at:.... During development I recently created a new model version and added a new entity, replaced some attributes etc... Working on the iOS app is fine because deleting the app clears all the data allowing me to work with a clean slate. On MacOS, I initially thought that I could simply navigate to the app group file location, delete the .sqlite file, along with the sqlite-shm and sqlite-wal. I also went and deleted the CloudKit related files. I did all of this out of pure ignorance - my expectation was that it would give me a clean slate, but it did not. This instead gave me some unpredictable behaviour, but the app was always in a bad state. the issues I saw were; • migration failure, • sqlite errors highlighting no such column: t0 - where all the
2
0
937
Nov ’23
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
Core Data Error - "NSCocoaErrorDomain" - code: 134060
Hi, I am implementing the synchronisation of SwiftData with CloudKit as described in the Apple Documentation titled - Syncing model data across a person’s devices. My app runs fine on iPhone without activating CloudKit under Signing and Capabilities option. But when activated, I get a CoreData error with a code: 134060. My app is in development stage. The following is the code snippet for your reference taken from the main structure adopting the App protocol. init() { do { #if DEBUG let schema = Schema([ Debit.self, Credit.self, ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) // Use an autorelease pool to make sure Swift deallocates the persistent // container before setting up the SwiftData stack. try autoreleasepool { let desc = NSPersistentStoreDescription(url: modelConfiguration.url) let opts = NSPersistentCloudKitContainerOptions(containerIdentifier: iCloud.com.sureshco.MyFirstApp) desc.cloudKitContainerOptions = opts // Load the store synchronously so it compl
0
0
545
Nov ’24
Core Data modifications not saved in two of three tables
I'm a bit lost because of a problem I never experienced before, however, I have a suspicion. I use Core Data for data storage and DB Browser for SQLite for inspecting the database running in the Simulator. Here's the relevant function where all Core Data handling happens: /** Creates a new ComposedFoodItem from the ComposedFoodItemViewModel. Creates the related FoodItem and the Ingredients. Creates all relationships. - Parameter composedFoodItemVM: The source view model. - Returns: A Core Data ComposedFoodItem; nil if there are no Ingredients. */ static func create(from composedFoodItemVM: ComposedFoodItemViewModel, generateTypicalAmounts: Bool) -> ComposedFoodItem? { debugPrint(AppDelegate.persistentContainer.persistentStoreDescriptions) // The location of the .sqlite file let moc = AppDelegate.viewContext // Create new ComposedFoodItem (1) let cdComposedFoodItem = ComposedFoodItem(context: moc) // No existing composed food item, therefore create a new UUID cdComposedFoodItem.id = UUID() // Fill data cdCo
1
0
455
Jan ’24
Core Data modifications not saved in two of three tables
I'm a bit lost because of a problem I never experienced before: I create entries in 3 Core Data tables and link them. As long as the app is open, everything is fine, I can see the database entries in the three tables. Once the App is closed and restarted, however, the new entries in two of the three tables are gone. I use Core Data for data storage and DB Browser for SQLite for inspecting the database running in the Simulator. Here's the relevant function where all Core Data handling happens: /** Creates a new ComposedFoodItem from the ComposedFoodItemViewModel. Creates the related FoodItem and the Ingredients. Creates all relationships. - Parameter composedFoodItemVM: The source view model. - Returns: A Core Data ComposedFoodItem; nil if there are no Ingredients. */ static func create(from composedFoodItemVM: ComposedFoodItemViewModel, generateTypicalAmounts: Bool) -> ComposedFoodItem? { debugPrint(AppDelegate.persistentContainer.persistentStoreDescriptions) // The location of the .sqlite file let moc = A
1
0
376
Sep ’24
CloudKit UICloudSharingController `recordChangeTag specified, but record not found`
Hello! I'm using NSPersistentCloudKitContainer for storing data and UICloudSharingController for sharing. Here's how UICloudSharingController is created: func share(_ record: Record, avatar: UIImage) { let controller = shareControllerForRecord(record, avatar: avatar) controller.delegate = self controller.popoverPresentationController?.sourceView = self.view controller.popoverPresentationController?.permittedArrowDirections = [] present(controller, animated: true) } func shareControllerForRecord(_ record: Record, avatar: UIImage) -> UICloudSharingController { if let share = share(for: record) { let controller = UICloudSharingController(share: share, container: self.cloudKitContainer) return controller } else { let controller = UICloudSharingController { [weak self] (controller, completion: @escaping (CKShare?, CKContainer?, Error?) -> Void) in guard let self = self else { return } self.persistentContainer.share([record], to: nil) { objectIDs, share, container, error in if let share = share { rec
0
0
810
Oct ’22
Crash during batch deletion merge when positive fractional decimals are stored and used in a derived attribute
I am experiencing a crash when performing a batch delete and merging changes on a Core Data store that uses NSPersistentCloudKitContainer. The crash appears to be triggered when positive fractional Decimal values are stored in a TransactionSplit entity (those values are aggregated via a derived attribute in the AccountTransaction entity). If I store whole numbers or negative fractional decimals, deletion seems to work correctly. I suspect that the issue is related to the internal representation of positive fractional decimals in conjunction with a derived attribute. Data Model Setup: Account (1:N relationship → AccountTransaction) AccountTransaction (1:N relationship → TransactionSplit), which contains a derived attribute (e.g., “splits.amount.@sum”) that computes the sum over the “amount” attribute on its related TransactionSplit objects. TransactionSplit, which contains a stored Decimal attribute named “amount” (of type Decimal/NSDecimalNumber). Steps to Reproduce: Insert sample data where each Tra
4
0
610
Mar ’25
WidgetKit with Data from CoreData
I have a SwiftUI app. It fetches records through CoreData. And I want to show some records on a widget. I understand that I need to use AppGroup to share data between an app and its associated widget. import Foundation import CoreData import CloudKit class DataManager { static let instance = DataManager() let container: NSPersistentContainer let context: NSManagedObjectContext init() { container = NSPersistentCloudKitContainer(name: DataMama) container.persistentStoreDescriptions = [NSPersistentStoreDescription(url: FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group identifier)!.appendingPathComponent(Trash.sqlite))] container.loadPersistentStores(completionHandler: { (description, error) in if let error = error as NSError? { print(Unresolved error (error), (error.userInfo)) } }) context = container.viewContext context.automaticallyMergesChangesFromParent = true context.mergePolicy = NSMergePolicy(merge: .mergeByPropertyObjectTrumpMergePolicyType) } func save() { do { try c
7
0
286
May ’25