Questions tagged [fetchrequest]
45 questions
29
votes
2 answers
SwiftUI macOS fetch json error [logging] volume does not support data protection, stripping SQLITE_OPEN_FILEPROTECTION_* flags\
I tired to build an macOS application (Xcode 12, SwifUI) for my IOS app.
To fetch json data from my website I need a fetch request (no API key). I found several samples on medium, hackingwithswift etc., but I always get keeping the same…

DoTryCatch
- 1,052
- 6
- 17
11
votes
3 answers
How to use a @FetchRequest with the new searchable modifier in SwiftUI?
Is it possible to use the new .searchable in combination with @FetchRequest?
I have a code like this:
struct FooListView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(
sortDescriptors:…

gurehbgui
- 14,236
- 32
- 106
- 178
6
votes
3 answers
How to show sample data in PreviewProvider when using FetchRequest
I have an SwiftUI View like this:
import SwiftUI
struct ReView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(
entity: Re.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \Re.name,…

gurehbgui
- 14,236
- 32
- 106
- 178
3
votes
1 answer
json.decode(response.body)..."Here response.body is not working..."
Please help me...
I just tried this code:
**try {
final response = http.get(url); // Giving error here
final extractedData = json.decode(response.body);
} catch (error) {
throw error;
}**
Error…

shivam goyal
- 45
- 5
3
votes
1 answer
Binding in a ForEach in SwiftUI
I use a FetchRequest to fill the elements. Then I'm using a list and want to display some kind of todo elements where you see which one is checked and which one not. Therefor I created a CheckBoxView.
My problem now is, that I need to pass a binding…

gurehbgui
- 14,236
- 32
- 106
- 178
3
votes
3 answers
SwiftUI: ObservableObject doesn't work with fetchRequest init
I have an ObservableObject declared like this in my DateView:
import SwiftUI
class SelectedDate: ObservableObject {
@Published var selectedMonth: Date = Date()
var startDateOfMonth: Date {
let components =…

mallow
- 2,368
- 2
- 22
- 63
3
votes
1 answer
SwiftUI - Variable 'self.fetchRequest' used before being initialized
I am trying to make dynamic filters of Core Data items with SwiftUI.
Core Data Entity: Item. Attributes: date (Date), done (Boolean), name (String).
Provided code creates 3 instances of Item entity. Above the list there is a segmented control to…

mallow
- 2,368
- 2
- 22
- 63
3
votes
1 answer
How do I transform SwiftUI fetch request results based on related objects?
I am building a SwiftUI list where I need a dynamic predicate. The approach is discussed here: https://www.hackingwithswift.com/books/ios-swiftui/dynamically-filtering-fetchrequest-with-swiftui
Here is my code so far:
struct SomeView: View {
…

Jaanus
- 17,688
- 15
- 65
- 110
2
votes
0 answers
SwiftUI Using on Receive with @FetchRequest Publisher
I try to observe the changes in @FetchRequest publisher by using onReceive as shown in the code bellow, It's work but I have on issue I want to fix it, the publisher publish to many values and I just want to receive one value to know the change in…

Ammar Ahmad
- 534
- 5
- 24
2
votes
2 answers
How to initialize @FetchRequest optionally
I have following code in my SwiftUI project
@FetchRequest private var step: FetchedResults
private var processID: UUID
private var stepID: UUID?
init(procID: UUID, stepID: UUID?) {
if stepID != nil {
let predicate =…

Dawy
- 770
- 6
- 23
2
votes
2 answers
SwiftUI and Core Data: Using a fetch request with instance member as argument inside a view
I seem to be caught in a Catch-22 situation. Perhaps my approach is entirely wrong here. I hope someone can help. I want to create a star-based rating display using feedback from users who visit a particular real world landmark.
In CoreData I have…

Hyoryusha
- 175
- 1
- 11
2
votes
2 answers
NSPersistentDocument FetchRequest warp property crash on macOS Document App SwiftUI project
Project create usinging Xcode macOS Document App template, with Use Core Data checkbox checked.
Add a Book entity to Document.xcdatamodeld
Add FetchRequest warp property to ContentView,
@FetchRequest(entity: Book.entity(), sortDescriptors: []) var…

Donly
- 55
- 8
1
vote
1 answer
Fetch Request Predicate to filter a Core Data entity where a small NSSet is contained within larger NSSet
I'm writing a 100% SwiftUI app with iOS and macOS targets, using Core Data and NSPersistentCloudKitContainer to backup to iCloud and sync between devices signed into the same AppleID.
The three entities involved are: Meals, Portions, Foods
Each Meal…

andrewbuilder
- 3,629
- 2
- 24
- 46
1
vote
0 answers
Using @SectionedFetchRequest , the section.id changed when i reopen my app
I build a todo app by using @SectionedFetchRequest to fetch the CoreData in IOS 15, I have two entity, one is "group" , the other is "Item", the relationship such as below:
the code is here:
// fetch request
@SectionedFetchRequest(
…

Chr1s78
- 33
- 1
- 5
1
vote
1 answer
How can I get Data from NSFetchRequest without return Array (Core Data)
I don't want FetchRequest to return [QuestionCD] array. Can't FetchRequest return QuestionCD to me?
each test has a unique title. There are 50 questions in total in a test. The title here determines the category of the questions.
With this function,…

Ufuk Köşker
- 1,288
- 8
- 29