Questions tagged [fetchrequest]
45 questions
1
vote
1 answer
CoreData won't find Entity @FetchRequest
I am trying to use Core Data. I created a new entity with attributes but my Fetch Request always says it can't find it.
I'd really appreciate the help
ContetView:
struct ContentView: View {
@FetchRequest(entity: Recipe.entity(),…

nico_p2000
- 23
- 5
1
vote
2 answers
Swift - Get one-to-many relationship
let's imagine that we have 2 entities:
-People (name, age, ..)
-House (color)
we recorded the data several times with house.addToPeople (newPeople) for each house
we want to get all the people of the house colored blue
how do we fetch this?
I tried…
user14861636
1
vote
1 answer
SwiftUI: Core Data @FetchRequest and List displaying managed objects - losing data on lockscreemn
I have issue with losing data in Core Data managed objects (all properties in spite of .objectID) are getting to be nil after going lockscreen and back.
I have been debugging this and found such issue.
struct SimpleContactsList: View {
…

Michał Ziobro
- 10,759
- 11
- 88
- 143
1
vote
2 answers
Using @FetchRequest results inside a parent view
I'm trying to abstract some components into smaller parts. For this I created the following listing:
struct ArticleList: View {
var fetchRequest: FetchRequest
var results: FetchedResults { fetchRequest.wrappedValue }
…

Tobias Tom
- 43
- 5
1
vote
1 answer
SwiftUI @fetchrequest not updating my view
I have a view which uses the @fetchrequest wrapper to pull in from CoreData, it works fine however, but when I edit the data in a .sheet and return to the view, the data is not updated until I navigate away and come back. Shouldn't it just update…

Northcott
- 11
- 2
1
vote
0 answers
SwiftUI List based on @FetchedRequest and filtering computed properties crashes
I have such code that has @FetchRequest loading Contacts then I have computed properties doing filter based on @State variable
@FetchRequest var fetchRequest: FetchedResults
private var contacts : Array {
…

Michał Ziobro
- 10,759
- 11
- 88
- 143
0
votes
0 answers
SectionedFetchedRequest object selection in SwiftUI
With this code I save a selected Student from a list generated from FetchRequest:
@FetchRequest var studentsFetchRequest: FetchedResults
@State private var selectedStudent: Student?
var body: some View {
List(studentsFetchRequest, id:…

arroyot24
- 39
- 1
- 4
0
votes
1 answer
Why is the app crashing when doing a Fetch Request in Core Data
Core Data is crashing when doing a fetch request but I can't understand why. The error is suggesting EXC_BAD_ACCESS but it doesn't always occur for this particular fetch request. Basically when I zoom in and out on the mapView (MKMapKit), it's at…

Chris
- 247
- 1
- 4
- 17
0
votes
1 answer
SwiftUI - How do I write a fetch request to return the largest value on each date?
I am creating a workout tracking app and trying to plot the largest weight value on a day over time for a given exercise. The entity "ExerciseSet" contains attributes dateCompleted and weight. There are multiple ExerciseSets saved on the same date,…

Rachel
- 51
- 1
- 7
0
votes
0 answers
Swift Core Data: FetchRequest with predicate over children
I have a Category entity with Scan child entities (one to many relationship).
Now I would like to fetch all Categories with a running a predicate on the children.
Details:
Category has a child relationship of Scans which is a Set.
Scan has an isSent…

Pete
- 213
- 1
- 13
0
votes
1 answer
Updating a `SectionedFetchRequest` when `scenePhase` changes
I’ve run into an issue with my app. It’s a simple Core Data app using a @SectionedFetchRequest to grab and format my data into a list.
The sectionIdentifier I’ve written checks the entry date against Calendar and formats the date accordingly…

ragavanmonke
- 409
- 3
- 13
0
votes
0 answers
Prevent refresh of @FetchRequest if view's @State changes
Scenario
I have implemented a parent view which contains a list of CoreData objects (populated using a predicate and @FetchRequest) and a toolbar. If the user scrolls down in the list, the toolbar is hidden in any case. If the user scrolls up, the…

Sebastian
- 115
- 1
- 8
0
votes
0 answers
Swift5 and CoreData: Sorting fetchRequest by related Entity-Attributes
Even if I run the risk of asking a question twice and I'm too blind to see:
How can I sort a FetchRequest by an Attribute of an related Entity. In my special case, I've got three tables:
Client <-> ClientToContacts <-> Contacts. In a List View I…

mihema
- 158
- 1
- 10
0
votes
1 answer
Loading CoreData in function SwiftUI, with NSFetchRequest Error
import SwiftUI
import Foundation
import CoreData
//MARK: - Welcome View
struct fetchView: View {
//MARK: - View
var body: some View {
let testing = getFetch()
ForEach(testing) {test in
}
…

Fausto IV
- 5
- 1
0
votes
0 answers
How can I set a fetchLimit dynamically for a SwiftUI @FetchRequest?
I am using a FetchRequest in a chat app and want to set the fetchLimit dynamically. First I want to load 50 messages, then an additional number when the user scrolls to the top of the chat message list.
I am using the following code:
@FetchRequest…

alionthego
- 8,508
- 9
- 52
- 125