I have successfully added Core Data to my SwiftUI project. I need to filter the results by type. When I add a predicate to the fetch request the app crashes at the point where the view containing the fetch request tries to load.
The error is Thread 1: EXC_BAD_ACCESS (code=1, address=0x1)
@Environment(\.managedObjectContext) var managedObjectContext
@FetchRequest(entity: Task.entity(),
sortDescriptors:[
NSSortDescriptor(keyPath: \Task.type, ascending: true),
NSSortDescriptor(keyPath: \Task.totalScore, ascending: false),
],
predicate: NSPredicate(format: "type == %@", Int16(1))) //this is the line that crashes the app
var tasks: FetchedResults<Task>
If I change the Int16(1) to Int16(0), the app does not crash but no data appears in the list.
This is the first app I have witten using core data so I need help.
Stringor a value that Swift can implicitly convert to aString, so what placeholder would you use for anInt?