Questions tagged [core-data]
Core Data is Apple's object modeling and persistence framework for iOS, iPadOS, tvOS, watchOS, and macOS. Xcode provides an object model editor for specifying entities, attributes, and relationships.
core-data
32,113 questions
3
votes
0
answers
105
views
(Initially) getting duplicate results from FetchedObjects
I'm taking a class to try to learn iOS programming, and am working on a class project related to Core Data, filtering, and sorting. The class is doing a poor job teaching, but I'm close. I don't want ...
0
votes
0
answers
63
views
Remove entity from NSPersistentCloudKitContainer
I'm using NSPersistentCloudKitContainer and I have added an entity (to the private database) to the core data model. Now I have realised that I don't need that ...
0
votes
1
answer
82
views
SwiftData iOS 26: Model inheritance breaks when another model has relationships to the parent class
I'm testing SwiftData model inheritance (new in iOS 26) and encountering a crash when combining:
A model that inherits from another model
A separate model with relationships to the parent class
...
0
votes
0
answers
18
views
CoreData: openDirectory error when saving data
If I save data in my CoreData app, I get the following info in my Xcode console:
cannot open file at line 42184 of [554764a6e7]
os_unix.c:42184: (0) openDirectory(/Users/christiankrueger/Documents/...
0
votes
0
answers
56
views
CoreData's automaticallyMergesChangesFromParent causes SwiftUI view to update twice
I have the following CoreData stack in my app:
...
Best practices
0
votes
5
replies
95
views
What is the most efficient way to display information about CoreData's relationship in SwiftUI
I have a CoreData entity Topic which has a one-to-many relationship to Question (questions ...
2
votes
1
answer
204
views
Warning "Public import of 'CoreData' was not used in public declarations or inlinable code"
In my App.xcdatamodeld I have an entity called File.
When I am building the project with Xcode, file FileEntity+CoreDataProperties.swift is generated.
After upgrading Xcode to version 26.0 (17A324), I ...
0
votes
1
answer
80
views
iOS Quick Start migration: How can I prevent my CoreData from being transferred to a new device? [closed]
I’m building a Swift app that uses CoreData (SQLite) for local data storage.
When a user sets up a new iPhone via Quick Start (device-to-device transfer), the app’s Core Data database is transferred ...
-4
votes
1
answer
79
views
Trigger ViewModel update deep inside navigation stack [closed]
I have a view model with a published array foodItems, containing the data for a List in the related parent View. The array is initially filled from CoreData by ...
1
vote
1
answer
254
views
How Can I Retrieve All SwiftData Values at Runtime?
I'm working with SwiftData and trying to replicate behavior similar to what I used to do with CoreData, where I had an extension ...
0
votes
0
answers
158
views
Simplify Core Data fetch request using async/await while respecting thread confinement rules
I understand managed objects are not thread safe with Core Data, so if you need to access their properties on a different thread you need to get a new managed object via the ...
0
votes
0
answers
130
views
ShieldConfigurationExtension & SwiftData
I am developing a Screen Time App for iOS and I am having issues with the ShieldConfigurationExtension (...
0
votes
0
answers
44
views
How can I propagate undo actions from a Core Data background context to the main context in a macOS app?
I’m using Core Data in a macOS app and performing most work in a background context. However, I’d like to take advantage of Core Data’s built-in undo functionality and I’m struggling with how to ...
0
votes
0
answers
74
views
How to allow Cloud Encryption in CoreData and CloudKit?
How to migrate if the following problem occurs?
The current Coredata and CloudKit database contains records which do not use allowCloudEncryption. Since we thought of advanced data protection for user'...
0
votes
0
answers
62
views
Updating sort order of items in a LazyVGrid
I have a grid setup where I'm displaying multiple images which is working fine. Images are ordered by the date they're added, newest to oldest.
I'm trying to set it up so that the user can change the ...
0
votes
0
answers
64
views
Core Data encryption using key that store in the keychain
I'm using Core Data in my iOS application, and I want to encrypt some string properties using AES with a key that is generated and saved in the keychain.
I'm using ValueTransformer to encrypt/decrypt ...
0
votes
0
answers
91
views
How to fetch an array of an attribute of an entity in order in Core Data?
I have a large list of book entities shown in a SwiftUI list (Around 10k to 50k books). I want to capture the ids of the list of books in the array in order when the user tap a list row.
The issue is ...
0
votes
1
answer
162
views
SwiftData - fetch all entities
In Core Data, I use the following code to fetch all entities with a name:
...
0
votes
0
answers
36
views
Is it possible to revert committed deletion from Core Data Cloudkit in Swift?
A user has accidentally deleted a root record that removes all data from the user. The data is stored in Cloudkit CoreData with Transaction History enabled.
I have noticed in the CoreData database ...
0
votes
1
answer
57
views
How to tell the source of the changed coredata objects in NSManagedObjectContextObjectsDidChange
I need to know the source of the changed coredata objects returned from NSManagedObjectContextObjectsDidChange. I have some shared objects, and want to send a notification if the source is other than ...
0
votes
0
answers
17
views
Cloudkit references do not reflect coredata relationships
In core-data I have a contact and location entity. I have one-to-many relationship from contact to locations and one-to-one from location to contact. I create contact in a seperate view and save it. ...
0
votes
0
answers
180
views
Action extension loadItem(forTypeIdentifier:options:completionHandler:) not running when saving directly from screenshot thumbnail
I am trying to save a screenshot to my app using an action extension directly from the screenshot thumbnail you see as soon as you take a screenshot but the method loadItem(forTypeIdentifier:options:...
-2
votes
1
answer
211
views
NSManagedObjectContext perform: Sending value of non-Sendable type
Swift 5
How to resolve warnings:
'Sending value of non-Sendable type '() throws -> ()' risks causing data races; this is an error in the Swift 6 language mode'
for this code:
...
-1
votes
1
answer
84
views
Is it ok to make a CoreData entity Identifiable?
I am new to CoreData but I made an object that I intend to use an array of within a ForEach loop in SwiftUI.
In the entity editor I added a UUID attribute stored_id....
0
votes
0
answers
81
views
CoreData: Getting Crash 'Cannot save objects with references outside of their own stores'
I am getting crash 'Can not save Object with references outside of their own stores' while decoding NSManagedObject. Here is the detail.
I have two NSManagedObjects. Parent: FitnessWrapper and Child: ...
0
votes
0
answers
144
views
Why SwiftData displays empty properties without values for objects fetched from Cloudkit?
This is my definition of Model for SwiftData:
...
0
votes
0
answers
48
views
Why Core Data @FetchRequest returns 0 objects while it should not?
Here is my @FetchRequest for User entity:
...
0
votes
1
answer
56
views
App data update issue thru Core data sync to CloudKit
I have setup push notifications and updates in CK are updating UI well.
The issue I have is Syncing between Core Data and CK.
It's set to use NSPersistentCloudKitContainer with ...
5
votes
1
answer
868
views
SwiftData Custom Migration Always Fails - Possible Bug in SwiftData
I'm using SwiftData in my SwiftUI iOS app, and I need to implement a MigrationPlan before launching, so things go smoothly later when I need to make changes to the ...
0
votes
1
answer
47
views
Access value of convenience property in custom NSManagedObject class in Objective-C causing crash
I would like to create a temporary BOOL property in a custom NSManagedObject class to track whether an async download of a remote image is underway so as not to start a second download while the first ...
0
votes
1
answer
58
views
CoreData in framework crash when using Preview
I have a project with 3 targets:
main application
an extension
framework (with coredata management for sharing with main app and extension)
I set App Groups for main app and extension.
When I trying ...
1
vote
0
answers
227
views
SwiftData/CoreData: 'Sending context risks causing data races' when sharing contexts between actors
In my app, I've been using ModelActors in SwiftData, and using actors with a custom executor in Core Data to create concurrency safe services.
I have multiple actor services that relate to different ...
0
votes
0
answers
60
views
ios app crashes intermittently on core data entities - Multiple NSEntityDescriptions claim the NSManagedObject subclass
The ios app works when hooked to a mac and run in debug mode, sometimes it fails. When I clean and rebuild it works for sometime and then fails again. Also if I start the app sometimes it works, ...
0
votes
0
answers
68
views
For loop of NSManagedObjects causing error at runtime
I am trying to loop through an array of ManagedObjects in Swift (that should have just one item) and am getting an error at runtime of
Thread 57: Fatal error: NSArray element failed to match the ...
0
votes
0
answers
64
views
CoreData : Custom sort descriptor for fetch in Fetched Results Controller
I have an entity with an attribute called "plainText" which stores text of type "String".
I want to fetch the objects based on a custom sort descriptor which is used in ...
-2
votes
1
answer
151
views
Best practice to seed/populate Core Data? [closed]
What is the right approach to seed Core Data database at the first launch?
I have sql db with precreated data.
I need to make this data available to the user at the app's first launch and then delete ...
-1
votes
1
answer
72
views
Swift core data variable number of relationships with tag on relationship
I am trying to build a graph of words, where each word has a relationship to each word with the same letters plus one, like for example :
...
0
votes
1
answer
270
views
CloudKit & NSPersistentCloudKitContainer - Fetch the CKRecord of creatorUserRecordID for every CKRecord in public database
I wasn't sure how to phrase the question. I know it's misleading.
Context:
I'm using NSPersistentCloudKitContainer for my public and private database. The CoreData model has two configurations: Local, ...
0
votes
0
answers
78
views
SwiftUI: change tracking with unmodeled NSManagedObject properties
I have a Core Data project, with my SwiftUI view hooked on to different properties of the attributes in the model, and the change tracking works great. I want to add a simple boolean property to my ...
0
votes
1
answer
32
views
Custom Merge Policy for Overwriting Relationships
Let's say I have a Person entity with various attributes of which one of its attributes has a uniqueness constraint so that there are no duplicate ...
0
votes
1
answer
71
views
How to efficiently delete CoreData relationship child objects
I have one-to-many relationship in CoreData defined in the following way:
...
2
votes
0
answers
88
views
Fetching ordered relationship with many items in Core Data is very slow
I have Library and Books entities where one library can contain many books where the relationship is an inherently ordered one in my app since the user can store the books in whatever order they want ...
0
votes
1
answer
402
views
Making CoreData singleton concurrency-safe
Consider this CoreData stack written for Swift 5.10
...
0
votes
0
answers
79
views
How to use SectionedFetchRequest in a view model?
I have a SwiftUI view that I want to move the fetch request in a view model.
For normal fetching I did it like this
Consider this model
...
0
votes
1
answer
156
views
CoreData: Grouped fetch by NSManagedObject
I'm inserting hundreds of thousands of objects using NSBatchInsert, now i want to add relationships between objects (let say A and B, with 1-to-many relationship) as no batch operation supports ...
0
votes
0
answers
51
views
CoreData Predicate for empty NSSet (One-to-Many relationship) [duplicate]
I have a CoreData entity called Item, which may or may not contain Properties. I would like to fetch all Items that have not yet ...
1
vote
0
answers
126
views
UUID issues with Swift and Core Data
I'm having an error at runtime related to the UUID in my code. Let me explain whats attached. Below are the Persistence Controller, DeflectionLogEntity, DeflectionLogViewModel, and the main issue, ...
0
votes
0
answers
65
views
CoreData re-encrypt string property
I'm using Core Data in my iOS application and I have one property that is encrypted using ValueTransformer:
...
1
vote
0
answers
44
views
How to make CoreData Manager with multi accounts?
My iOS app can change account.
SQLite file is saved to [account]_dbfile.sqlite.
If I logged in ABC named account, call CoreDataManager.shared.setup("ABC") ...
1
vote
1
answer
88
views
Core Data and NSSortDescriptor: Combining Values During Sort
Is it possible to apply a NSSortDescriptor that investigates two (or more!) keys while fetching from Core Data?
Currently we fetch the objects and sort them in ...