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.
29,136
questions
-2
votes
0
answers
18
views
How to save data in coreData when we fetch data from API and also use in other UI parts [closed]
Best way to store data in coreData without delay as we get data from API and also use that data in other parts of Application for UI update. Currently coreData take too much time to save that data.
...
1
vote
1
answer
32
views
Uint in CoreData?
When setting up a CoreData entity I can set its type to "Integer 16", "Integer 32" and "Integer 64" which represents Int16, Int32 and Int64 in Swift.
I need to store data ...
0
votes
0
answers
26
views
Why does using the perform method from Core Data in a Task block causes data corruption issues? [closed]
I am creating a new AudioFile NSManagedObject in my DataController class's persistent container view context.
I am noticing what I presume as 'Date Race' issues or the artwork property of AudioFile ...
-1
votes
0
answers
26
views
CoreData on SwiftUI: how to get a file location of particular attribute of coredata
Hi I am trying to airdrop a single item from attribute ([NSManagedObject]). I have written the following so far
let url = URL(string: "your url here")
let av = UIActivityViewController(...
0
votes
0
answers
32
views
Core Data database does not reflect changes made from widget extension in the main app
Ok, I simply have Main App and the Widget extension. There is a shared .xcdatamodel file between an app and extension. There is a Setting entity.
@objc(Settings)
class Settings: NSManagedObject, ...
0
votes
0
answers
54
views
save data under a ordered core data relationship
In my swift code below the goal is to save a string to a core data relationship. In class two there is a func that adds a string to the tableview in that class. But that added string is only displayed ...
0
votes
0
answers
16
views
Duplicated records with the same `objectId` in Core Data with CloudKit
I have a Swift App that uses Core Data with CloudKit. CloudKit duplicated all records in the container, across all of my devices. The duplicated records have the same objectId. My code uses ...
0
votes
0
answers
20
views
'Runs as Current User' on tvOS causes Core Data to reset
My app uses Core Data to store user data. It doesn't have login or profile mechanisms, because user data is tied to the user's Apple ID and synced via iCloud using CloudKit.
I've recently added the ...
0
votes
0
answers
24
views
BatchInsert Unable to update object relationships Coredata
I am trying to import high amounts of data and was suggested to use BatchInsert to efficiently import data. With the below code, I was able to import large volumes of data, however, the relationships ...
0
votes
0
answers
50
views
Download Core Data SQLite Data File From iPhone
I am trying to browse data that has been saved to Core Data from my application that I am running. The iPhone is running iOS 17 and I have Xcode 15.
Prior to this update, I used to be able to navigate ...
0
votes
1
answer
25
views
Core Data: 1:1 Relationship to other entity or keep everything in one entity?
I have an Entity in Core Data that contains multiple "small" attributes like String and Int. But I also have one binary attribute that contains ~500kb data.
This attribute is specific and ...
0
votes
0
answers
48
views
iOS App Architecture : Networking vs. Saving to Core Data/SwiftData
Background: Im building an iOS Bus scheduling app. I'm getting Bus Schedule and Bus Route information from a public API. The Bus Route information is large (25000 JSON records).
Challenge: Initially I ...
0
votes
0
answers
38
views
save a string to a core data relationship
In class Viewcontroller the user saves names to entity Person Attribute name. What I would like to do is when the user hits a name on a tableviewCell in class View controller and is segued to class ...
1
vote
0
answers
45
views
Missing Entries from Core Data Database
I am the developer of an open-source finance tracker Dime that is built on Core Data. In my recent v2 update, I changed my Core Data infrastructure a little - using a static shared instance of ...
1
vote
1
answer
46
views
How can I clear the core data?
my app crashes sometimes randomly when I try to log out and clear the Core Data. When I debug cachedResults.forEach { coreDataContext.delete($0) }, the app crashes on this line. How can I fix this? ...
0
votes
0
answers
17
views
SwiftUI: airdropping coredata object
I wanted to ask if there is a way to airdrop a coredata object from one device to another.
How to share an NSManagedObject from one device via airdrop and then receive it and use it on the other ...
0
votes
1
answer
23
views
Why SwiftUI List returns back when I add reference to selected object in the next step?
Question:
What is the best approach to avoid SwiftUI list returning back to beginning, when I save viewContext after adding reference from selected object to a child item?
How it should work:
Idea is ...
0
votes
0
answers
24
views
connect a tableview to a core data relationship
I am working to write a swift app that connects a singer to the songs they wrote. Which means in core data I will have to create a relationshp between 2 core data entites. So a singer can have many ...
-1
votes
0
answers
32
views
path not being found when trying to connect core data entities via relationships
I want to configure my code so that when a user clicks on a cell in class Viewcontroller and then is segue to Detail view controller it can save items to tableview in a way that it corresponds to its ...
0
votes
1
answer
49
views
Why is Persistent Container returning nil?
I have set up CoreData stack in my app, but the reference to NSPersistentContainer is returning nil in the PassWordTableVC.
App Delegate
var window: UIWindow?
func application(_ application: ...
0
votes
0
answers
45
views
How to fetch distinct results based on 1 property in Core Data but still fetch all properties?
My goal is to fetch distinct SearchHistoryItemModel.
My expected result:
[
{
id: "1", -> it's a String
keyword: "abcd", -> it's a String
timestamp: " time1 ...
0
votes
1
answer
30
views
AVPlayer only plays video after db is reseeded
I am using a series of 4 functions to manage playing a playlist of videos sequentially in AVPlayer.
func setupPlayer(path : String?) {
var url = currentVid!.url! //path ?? currentVid!.url!
...
-3
votes
0
answers
113
views
SwiftUI how to trigger a redraw when a member of a Core Data Entity changes? [duplicate]
How can I change this code so that ItemView is redrawn when item.name is updated, but without changing ItemView to depend on the Core Data Item object? (ItemView is in a library that doesn't/shouldn't ...
0
votes
1
answer
44
views
Retrieving Transformable of type [String] from Core Data
My Core Data attribute is set to Transformable with custom class in Model inspector set as [String]
I'm able to save data like this:
func saveResultsObjects(results: [String]) {
let entity = ...
0
votes
0
answers
15
views
CloudKit or something like CoreData
I want to create a app where the user can save data, but the user should be able to share this data with others. My question is, would you use CloudKit or something like CoreData. Or would you save ...
0
votes
0
answers
7
views
Sharing CoreData with CloudKit not creating link in production
I’ve been able to implement CoreData sharing with other iCloud users, mostly following Apple’s documentation.
After a lots, of tests I was happy with the result and sent the app to production, but ...
0
votes
0
answers
22
views
CoreData ensure combination of related objects is unique
NOTE: I deleted, then reposted this because the solution I thought I had doesn't work quite as expected.
Original Post:
I have a CoreData table that acts to bind different objects to each other.
How ...
0
votes
1
answer
81
views
Create new array when button is pressed
I want to create a new array every time when a button (ActionButton) is pressed. When this button is pressed the first time then a new array should be created and 10 should be added. When the button ...
0
votes
0
answers
34
views
How to add mutiple core data managedObjectContext to Environment SwiftUI app?
I am getting this error when I run the App "Thread 1: "The fetch request's entity 0x280a444d0 'SleepStoriesCD' appears to be from a different NSManagedObjectModel than this context's"
...
0
votes
0
answers
27
views
How to find CoreData Object via multiple relationships
I have a number of CoreData objects that are have multiple relationships. I'll focus on one, Answer. The CoreData relationships look like this:
It has no fields of its own, simply acts as a connector ...
0
votes
1
answer
61
views
SQLite columns are duplicated with a number in the attribute name (Core Data)
Inoticed that some of my attributes are duplicated in the SQLite file. For example I see two columns ZENDDATE and ZENDDATE1. The same for some other columns.
Why does it happen? How can I get rid of ...
0
votes
2
answers
76
views
How to safely access Core data NSManagedObject attributes from a SwiftUI view using swift concurrency model?
How do I safely access Core data NSManagedObject attributes from SwiftUI view using the swift concurrency model.
My understanding is we need to enclose any access to NSManageObject attributes in await ...
0
votes
0
answers
19
views
Coredata loss all data with CloudKit sometimes
I have enabled iCloud synchronization in my app, but I may encounter this situation: this morning, I opened the app to record data, and then went to use another app. After a while, when my phone's ...
0
votes
0
answers
39
views
CoreData predicate using subquery
I have two CoreData entities with their properties:
Asset
caches: [Cache] (to-many)
Cache
key: String
value: String
asset -> Asset (to-one, inverse of caches)
I want to make a NSPredicate which ...
0
votes
1
answer
38
views
CoreData takes too long to save a Dictionary
I'm saving a dictionary with 1000 items and it takes around 3/4 seconds to do it. Which seems to me like a really long time. This happens successfully when I call addEmojisDictionary. Is there a way ...
0
votes
0
answers
29
views
App Crashes on test flight after installing due to CoreData Migration
I have an older version of my app on testflight. I added 2 entities to coreData and I was not familiar with the migration requirements. Now my app crashes with the following error on the piece of code ...
-1
votes
1
answer
34
views
Generic parameter 'T' could not be inferred for 'Optional<Array<_>>'
I'm getting this error
Cannot convert value of type 'Optional<Array<_>>' to specified type
'[FoodEntity]'. Generic parameter 'T' could not be inferred
func fetch<T:...
0
votes
1
answer
63
views
SwiftUI List view return error Type '()' cannot conform to 'View with core data
I have implemented core data with required function. I am trying to call function into view , when we do not have data into core data , that time I am making network call and save the data into core ...
-1
votes
0
answers
20
views
Strategies for de-duplicating records in a public CloudKit database
Since CloudKit doesn’t support unique record constraints I’m looking for strategies and code samples (if it’s possible) for de-duplicating records in a public database in CloudKit.
I have seen code ...
0
votes
0
answers
15
views
Case in-sensitve search with case sensitive sections
In Core Data on iOS, I want to do a @SectionedFetchRequest with a predicate that does an case in-sensitive search on a field named "title" as the sectionIdentifier. I want the results to be ...
0
votes
0
answers
26
views
How to pass an attritube to make a dynamic predicate in Swift if computed property doesn't work? [duplicate]
I'm working on flashcards app and found an issue with my logic. First of all, I want to pass the @Binding variable representing the [Int] with the name selectedCategories(represent categories which ...
0
votes
1
answer
36
views
Swift PreviewProvider failing to initalize view variable
I am using CoreData in a SwiftUI project with a relationship as follows:
Climb:
- timestamp: Date
- grade: Int16
- attempts: Int16
...
Session:
- timestamp: Date
- climbs: [Climb] # A list of Climb ...
0
votes
1
answer
75
views
Calling objectWillChange.send() produce performance issues
I have a project with a nested object structure
Project -> Panels -> Layers
and I have SettingsView where I update different properties of any of these structures.
On every update I have to call ...
-1
votes
0
answers
44
views
Can improper handling of core data light weight migration lead to recurrent crashes?
Context:
I am working on a legacy codebase. App uses the core data for a very simple use case. Core data stack is set up using Objective-C
- (NSManagedObjectContext *)managedObjectContext
{
if (...
0
votes
0
answers
69
views
Display iCloud sync status to user
I am using Core Data and iCloud sync setup with NSPersistentCloudKitContainer. When the user opens the app on a second device for the first time, it takes some time before the iCloud fetches all the ...
0
votes
0
answers
28
views
Adding data to Core Data if there is no data on device and no data in iCloud
For an app I'm building I want to setup the app for the user when opening the app for the first time. This means creating a list (ListEntity) in Core Data. I do this in the persistence controller. (I ...
0
votes
0
answers
28
views
Encountering "nilError" when saving new Core Data entity in SwiftUI
I'm building an app using SwiftUI and Core Data, and I'm encountering an issue when trying to save a new Core Data entity. I'm getting a "nilError" when attempting to save the entity, and I'...
0
votes
1
answer
39
views
Why can't I force cast an NSManagedObject in my Core Data unit test?
I have a simple entity called 'Lift' and this simple unit test:
func testLiftEntityCreation() {
let lift = NSEntityDescription.insertNewObject(forEntityName: "Lift", into: ...
0
votes
0
answers
228
views
SwiftData insert Relationship large array
I'm trying to use SwiftData with a large amount of objects and it seems there is very bad performance when inserting items.
For example I have a child model that looks like below. Notice I didn't set ...
0
votes
0
answers
20
views
Can't set NSMergePolicy to my view context
Here is my CoreData container setup code:
private func _setupContainer() {
persistentContainer = .init(name: "MyAppName")
let storeDescription = persistentContainer....