32,117 questions
-1
votes
0
answers
84
views
How to connect Swift actor to a managed object context defined in MainActor isolated stack
I have the following CoreData stack:
@MainActor
final class CoreDataStack {
static let shared = CoreDataStack()
let privateContext: NSManagedObjectContext //used for database read/writes, ...
0
votes
0
answers
55
views
CoreData's automaticallyMergesChangesFromParent causes SwiftUI view to update twice
I have the following CoreData stack in my app:
let mom = NSManagedObjectModel(contentsOf:modelURL)!
managedObjectContext = NSManagedObjectContext(concurrencyType:.mainQueueConcurrencyType)
...
Best practices
0
votes
5
replies
84
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 with inverse relationship being topic). Each Question contains the previousAttempt property.
I am working on ...
2
votes
1
answer
166
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
78
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
77
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 calling the loadFoodItems function.
...
1
vote
1
answer
211
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 on NSManagedObjectContext that allowed me to fetch all stored objects, ...
0
votes
0
answers
112
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 objectID from the ...
0
votes
0
answers
106
views
ShieldConfigurationExtension & SwiftData
I am developing a Screen Time App for iOS and I am having issues with the ShieldConfigurationExtension (ShieldConfigurationDataSource). I know this extensions is sandboxed but I should be able to read ...
0
votes
0
answers
40
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
65
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
52
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
63
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
89
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
135
views
SwiftData - fetch all entities
In Core Data, I use the following code to fetch all entities with a name:
func fetchAllEntities(for entityName: String) -> [NSManagedObject]? {
let fetchRequest = NSFetchRequest<...
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
16
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
171
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
193
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:
import CoreData
...
-1
votes
1
answer
73
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. Then in an extension I wrote this:
...
0
votes
0
answers
80
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
122
views
Why SwiftData displays empty properties without values for objects fetched from Cloudkit?
This is my definition of Model for SwiftData:
import SwiftData
@Model
class TerritoryGroup {
var name: String?
var territories: [Territory]?
init(name: String) {
self.name = name
...
0
votes
0
answers
48
views
Why Core Data @FetchRequest returns 0 objects while it should not?
Here is my @FetchRequest for User entity:
struct SettingsView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(
entity: User.entity(),
...
0
votes
1
answer
50
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
739
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 data being saved.
For example, ...
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
53
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
212
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
58
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
67
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
62
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
128
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 ...
0
votes
0
answers
54
views
CoreData/CloudKit 0xdead10cc
I’m getting a 0xdead10cc crash in a basic CoreData/CloudKit application. I only have one CoreData save call and it's made when the app is in the foreground and it's minor so I don't think it's being ...
-1
votes
1
answer
71
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 :
table -> ablate, cablet, tabled, gablet, albeit, albite, ...
0
votes
1
answer
258
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
77
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
0
answers
48
views
CoreData + CloudKit Sync Issues: Observed Context Saves and Skipped Migrations
I am using CoreData with CloudKit in my iOS app, and I have encountered a series of issues while syncing data. The logs show multiple context saves and migration skips, but there’s no clear indication ...
0
votes
1
answer
31
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 Person entities.
It has an unordered to-many ...
0
votes
1
answer
65
views
How to efficiently delete CoreData relationship child objects
I have one-to-many relationship in CoreData defined in the following way:
private func configureOneToManyRelationship(sourceEntity: NSEntityDescription,
...
2
votes
0
answers
86
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
349
views
Making CoreData singleton concurrency-safe
Consider this CoreData stack written for Swift 5.10
import CoreData
final class CoreDataStack {
static let shared = CoreDataStack()
private init() { }
lazy var ...
0
votes
0
answers
76
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
class MyType {
let title: String
let category: String
...
0
votes
0
answers
114
views
Issues with Updating Widget Timeline Based on SwiftData/CoreData Changes in WatchOS App
I tried looking everywhere online and asked AI, but it seems none of the solutions resolved my issue. I am using CoreData or SwiftData with CloudKit to fetch data from the database. I created a simple ...
0
votes
0
answers
57
views
How to implement multiple-entity UICollectionViewDiffableDataSource with Core Data?
I have a UICollectionView populated with a diffable data source being populated with Core Data managed objects from an NSFetchedResultsController. It is based on this tutorial by Antoine Van Der Lee. ...
0
votes
1
answer
153
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
28
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 been assigned any Properties.
extension Item {
@nonobjc public ...
1
vote
0
answers
122
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:
class EncryptedStringTransformer: ValueTransformer {
private var encryptionKey: String
init(...
1
vote
0
answers
40
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") and fetch, save blahblah...
Then, ...