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
Filter by
Sorted by
Tagged with
1 vote
1 answer
451 views

SwiftData with ValueTransformer similar to core data

In Core Data, you are able to use ValueTransformer to transform individual attributes to/from core data. This would be useful in cases like encrypting/decrypting certain attributes when storing/...
emirrou's user avatar
  • 31
6 votes
1 answer
631 views

Core Data : No NSValueTransformer with class name XXX was found for attribute YYY on entity ZZZ for custom `NSSecureUnarchiveFromDataTransformer`

I already saw this post which is about the same warning but I already have that approach and it does not fix this issue now in iOS 17 and Xcode 15. My use case is very simple, I have this custom ...
Vladimir Amiorkov's user avatar
0 votes
0 answers
126 views

iCloud Backup for .sqlite database file for CoreData in iOS Swift

I am currently working on an iOS project where I'm using Core Data for local data storage. Now, I'd like to upload my .sqlite database file to iCloud for synchronization and backup purposes. Can ...
Aniket Rao's user avatar
0 votes
0 answers
72 views

Receive NSPersistentStoreRemoteChange notification when app is closed

I use NSPersistentCloudKitContainer to fetch/sync data across multiple devices with the same iCloud account. /// ... container = NSPersistentCloudKitContainer(name: containerName) let description = ...
Stopee's user avatar
  • 239
0 votes
1 answer
100 views

How to create predicate to fetch core data entities by string property sorted as an integer?

I simply have a Month entity with property @objc(Month) class Month: NSManagedObject { @NSManaged var identifier: String //202311, 202301, 201912 and so on, always year and month as a components } ...
Bartłomiej Semańczyk's user avatar
0 votes
0 answers
64 views

How to fetch specific data based on user's choice in SwiftUI?

I'm working on a logic where the user is given a choice to mark the card categories he/she would like to study in the next study session, however, the current issue I'm facing is how am I going to ...
Ft klee's user avatar
  • 23
1 vote
1 answer
100 views

CoreData -> Multiple data stores based on some value

I have an odd need, and I suspect the answer is going to be "it's not meant to work that way", but here goes (and no, I haven't tried this yet) - I need to be able to hit various data stores ...
chornbe's user avatar
  • 1,136
0 votes
0 answers
57 views

CoreData: Request was cancelled because the store was removed from the coordinator

I am working with CoreData and WidgetKit. I would like to implement a NSPersistentCloudKitContainer into an interactive widget. However, when the user makes a change over the widget, the container ...
Nikodem's user avatar
  • 129
2 votes
0 answers
574 views

Observe property changes of all objects in SwiftData

In Core Data you can do something like this to observe property changes of all objects of a type: .onReceive(NotificationCenter.default .publisher(for: .NSManagedObjectContextObjectsDidChange) ) { ...
John's user avatar
  • 1,092
0 votes
0 answers
43 views

how to init multi dynamic fetch requests in one view?

One view needs multi dynamic fetchresults, so I write down the following code: @FetchRequest var dreamsForTheUser: FetchedResults<Dream> @FetchRequest var actionsForTheUser: ...
Tracy9988 Xu's user avatar
0 votes
1 answer
266 views

How can I lazy load objects from CoreData in a List View in SwiftUI

In the following code I'm loading Categories from CoreData into a List view in SwiftUI but for some reason the view seems a little slow when loading. What would be the best way to laze load objects as ...
fs_tigre's user avatar
  • 11k
1 vote
1 answer
333 views

CloudKit fetch latest changes from push notifications

I have an app which is available on multiple platforms (macOS, iOS, iPadOS, …) and my goal is to update widgets on each platform when CloudKit DB is changed without opening the app. Now, for example, ...
Stopee's user avatar
  • 239
0 votes
1 answer
81 views

Need help getting NSSecureUnarchiveFromDataTransformer to work

I am trying to implement NSSecureCoding but am getting some problems my code is this. a class called WrapperClass: public class WrapperClass:NSObject, NSCoding, NSSecureCoding { public static var ...
Thomas Wix's user avatar
0 votes
0 answers
135 views

How to make text update dynamically in SwiftUI?

I found a problem where the number of cards in the "stack" of cards is static and doesn't change as the cards are being removed. Is there a way the number of cards could be dynamic and ...
Ft klee's user avatar
  • 23
0 votes
0 answers
46 views

How to store date from Picker to Core Data?

I'd like to ask for an explanation why Dateformatter adds time and -1 day that I don't want. I need to save the date only in the format "yyyy-MM-dd" in the Date type field in Core Data let ...
user22038725's user avatar
0 votes
1 answer
478 views

SwiftUI View - initializer is inaccessible due to 'private' protection level

I have List in one view and upon selection of a row, would like to navigate to another View. I am trying to pass 'LocationInfra', a coredata entity to another ConfigProfileView. I get two errors in ...
vrao's user avatar
  • 533
1 vote
0 answers
59 views

How to use remove(at:) in the app with CoreData?

the problem I have is regarding the remove(at:) method which I want to use to be able to remove cards from the view after the user toggled the button. However, the issue I'm facing is that the array ...
Ft klee's user avatar
  • 23
0 votes
0 answers
39 views

Efficiently Querying Core Data with Multiple Stores: Finding Set Differences and Highest Priority

I'm working on a Core Data application with two separate stores: WordStore and StatusStore. These stores serve distinct purposes: StatusStore contains a single entity called Status with fields: word:...
Adele's user avatar
  • 39
0 votes
1 answer
162 views

How to efficiently use fetched objects from background thread in main thread?

I need to use NSManagedObjects instances in my UI. I understand that after fetching in background thread, in contrast to the objects themselves, NSManagedObjectID can be safely passed to main thread ...
malsag's user avatar
  • 144
0 votes
0 answers
29 views

Is the underlying Sqlite file of CoreData portable across platforms?

When CoreData is saving its data in a Sqlite file, is that file portable e.g. from iOS to macOS? I ask because from a testing perspective this might be helpful. When I tried examining such a file a ...
s_question's user avatar
0 votes
1 answer
63 views

Deleting CoreData object from a grouped (by Dictionaries) List in SwiftUI

I have an issue with Swipe to Delete on a grouped List in that it randomly deletes the wrong object. I understand that this comes from the (grouped) Lists index not matching the index of the object in ...
Benji's user avatar
  • 3
0 votes
0 answers
34 views

Setting Global View Context For Core Data in SwiftUI (Bad?, Good?)

Typically, we define @Environment(\.managedObjectContext) var context in View, then we can get context from it. My question is can I directly define a global context called dbContext in the below demo ...
LiangWang's user avatar
  • 8,414
1 vote
0 answers
69 views

How to avoid CoreData objects being assigned in 2 different CloudKit record zones?

I started the application with CoreData and everything worked great. I then migrated to CloudKit and things started going wrong. For the last few weeks I am regularly haunted by an error error: ...
Alex Ioja-Yang's user avatar
0 votes
0 answers
50 views

ForEach inside a List not showing results [duplicate]

I've got a view that draws its content from core data using a FetchRequest and stores the results in the var navigations. I want to display the content of navigations inside a List using a ForEach. I'...
Peel's user avatar
  • 49
1 vote
1 answer
589 views

SwiftData share extension blocks app from opening SQLite file

Using SwiftData and a shared SQLite database in an app and its share extension. If you merely tap Share in Safari, and the extension is shown, when you activate the app, one view throws: DraftsView : ...
bobsil's user avatar
  • 21
1 vote
0 answers
68 views

CoreData and CloudKit sharing, Swift

lazy var persistentContainer: NSPersistentCloudKitContainer = { let container: NSPersistentCloudKitContainer = NSPersistentCloudKitContainer(name: "MYNAME") let appGroupId: ...
manubrio's user avatar
  • 449
0 votes
0 answers
49 views

Core Data migration with empty tables inside DB

I wanted to create migration from Transformable to String. I created mapping model and entity policy class MigrationPolicy15to16: NSEntityMigrationPolicy { @objc func ...
scandyz's user avatar
0 votes
1 answer
173 views

Group Core Data items by category in List in SwiftUI

I have a Core Data container with two entities, a Category and an Item. The Item can have one Category assigned and the Category can be assigned to many Items. What I need to do is group the items by ...
fs_tigre's user avatar
  • 11k
0 votes
0 answers
33 views

Is there a benefit in encrypting SQLLite DB in iOS

If iOS already has passcode ( https://www.hexnode.com/blogs/iphone-encryption-everything-you-need-to-know/ ) we understand that storage is encrypted by default using AES In that case, is there any ...
lives's user avatar
  • 1,193
1 vote
0 answers
38 views

CoreData BUG?: Binding to NSAttributedString causes crash when removing entity from context

I'm taking a non-optional NSAttributedString from CoreData and passing it as a binding to be used in a UIKit UITextView. Everything works fine, except that the app crashes when deleting the CoreData ...
Konrad's user avatar
  • 33
0 votes
0 answers
55 views

Swift CoreData: NSFetchedResultsController with NSFetchRequestResult of type countResultType

I am trying to get number of objects fetched by the fetch request using NSFetchedResultsController with NSFetchRequestResult of type countResultType I implemented the fetch request, fetch request ...
abed's user avatar
  • 33
0 votes
0 answers
93 views

SwiftUI Selection Sets and Core Data - setting up NSPredicate with the object identifier

If you combine CoreData with SwiftUI Lists you can configure multiple selection of list items if the selection parameter of the list is Set<Item.ID>? The question is: if you have a set of Item....
obj-D's user avatar
  • 250
0 votes
1 answer
57 views

Refreshing picker after returning from child view

I have a view to add a new Inventory object. to do so it requires that you select a Vessel object from a picker that it's assigned to. If no Vessels have been created yet, it prompts you to bring up a ...
Peel's user avatar
  • 49
1 vote
0 answers
22 views

Easily sync CoreData and CloudKit

I have an app where I have enabled CloudKit and it works great for syncing across multiple devices. However where it doesn't work is syncing for a widget, where I've read the optimal approach is to ...
user11145365's user avatar
2 votes
2 answers
373 views

NSBatchInsert does not work for CoreData Transformable Attribute e.g. Dictionary<String, String>

CoreData doesn't import the data when using dictionaries in a transformable core data attribute. I'll attach screenshots of the setup and the project. Using a custom NSSecureUnarchiveFromData like [...
NilsBerni's user avatar
0 votes
1 answer
86 views

How to trigger button in one view and animate other object in another view in SwiftUI?

While creating animation logic so that when the button is pressed, the Card would swipe away, however, with the current approach by using State and Binding nothing happens. I suppose the trick here is ...
Kolea's user avatar
  • 13
0 votes
0 answers
44 views

iOS App Extension Widget not updating with CoreData

I have a simple app that uses CoreData defined as follows: let fetchRequest: NSFetchRequest<ListObject> = ListObject.fetchRequest() let fetchedResultsController = ...
user11145365's user avatar
0 votes
1 answer
1k views

Fopen failed for data file: errno = 2 (No such file or directory)

I have a large project that has several Core Data containers. When you first open the application on the simulator or on a real device, this error pops up in the debugger. fopen failed for data file: ...
Gucci's user avatar
  • 67
1 vote
2 answers
109 views

Is it necessary to have an inverse relation in CoreData

I have an existing Core Data entity in the production version of my app. I want to add a new entity that has a relation to the previous one but I read that you need to have an inverse relation as well....
Kevin Thomas's user avatar
0 votes
0 answers
47 views

Order data by the second field if the first field is empty

I want to solve this problem using Core Data tools. I am trying to build a MySQL query that has an order by statement. This is what I am trying to do: SELECT * FROM tbl_product ORDER BY ...
Michel Rivera's user avatar
0 votes
0 answers
25 views

How to replace all the existing expenseCategory saved in Core Data which are having same expense categoryName

For example I have number of expenses with “Food” expenseCategory which are saved in core Data. When I click the save Button under EditExpenseCategory view I want to change all the existing Food ...
mzkn's user avatar
  • 53
0 votes
0 answers
59 views

CoreData crash NSTaggedDate objectForKey

I'm using CoreData in my iOS application, I have a function that creates NSManagedObjectContext per thread: var contextDict = [Thread:NSManagedObjectContext]() var context:NSManagedObjectContext{ ...
YosiFZ's user avatar
  • 7,842
0 votes
1 answer
74 views

How do I get @FetchRequest to not momentarily include deleted objects?

When I delete Core Data objects from a background context, and call save() on the context, (and the view context has automaticallyMergesChangesFromParent = true), @FetchRequest in my view still ...
jsadler's user avatar
  • 609
0 votes
0 answers
56 views

How can I sort an NSFetchedResultsController by localized values?

I'm almost completely done localizing my app to support multiple languages but I've run into a sorting problem I can't solve. I have this entity: import Foundation import CoreData extension Lift { ...
Jim's user avatar
  • 1,290
1 vote
1 answer
62 views

Do Core Data derived attributes work properly with Cloudkit?

In my use case I have two entities List and Item that have an optional one to many relationship. I would like to have two non transient derived attributes on List: items.@count and items.@sum. Does ...
John Cashew's user avatar
  • 1,123
0 votes
1 answer
40 views

need to save a shuffled order in core data

I am attempting to shuffle the order of the array in core data. Right now the code shuffles the order it attempts to save the shuffle order but when I reload the class the original order is still ...
user13990880's user avatar
0 votes
0 answers
23 views

SwiftUI - How to create @FetchRequest with NSPredicate for the String and Date objects [duplicate]

I am trying to create @FetchRequest to get list of items which name contains “bill” and transaction dates are >= “2023-01-29” and transaction dates are =< “2023-08-29” using following @...
mzkn's user avatar
  • 53
1 vote
0 answers
53 views

NSBatchInsertRequest not updating content in some cases when perform

I'm facing a strange behaviour with NSBatchInsertRequest and I don't seems to understand what is causing my problem. I have some piece of code that updates local data depending on some remote data ...
Martin's user avatar
  • 1,003
0 votes
0 answers
29 views

shuffle core data attributes on a tableview

In my swift code it loads an attribute from core data entity Song attribute title. It is in a relationship with entity singer with its destination being singer. I want to shuffle the contents of what ...
Max's user avatar
  • 3
0 votes
1 answer
38 views

randomize contents of tableview cells

I what I have below is the code that loads string from core data named title. What I would like to do is have a func that randomizes the order of the way all the names are displayed on the tableview ...
Mos VIN's user avatar