The right way to fetch information from the core information and put the choices in a Picker so the person can decide, the chosen possibility must be saved in one other core information
after the person selects an possibility, ship that chosen possibility to a different entity within the core retailer.
so principally the concept is for the person so as to add classes, after which they need to have the ability to choose from the classes they added and ship the chosen one to a different entity within the code information
@FetchRequest(entity: Categoryes.entity(), sortDescriptors:[NSSortDescriptor(key: "name" , ascending: true)]) non-public var all_categories: FetchedResults<Categoryes>
@State non-public var title = ""
@State public var class = ""
@State non-public var date = Date()
@State non-public var worth = 0
@State public var is_allert = false
non-public func save_spending(){
if title.rely > 0 || worth > 0{
do{
let job = Spendings(context: viewContext)
job.title = title
job.class = class
job.date = date
job.worth = Float(worth)
attempt viewContext.save()
} catch {
print(error.localizedDescription)
}
title = ""
worth = 0
} else {
is_allert = true
}
}
var physique: some View {
Textual content("ADD EXPENSE")
Kind{
Part("Class of the expense"){
Picker("Choose a class", choice: $class, content material: {
ForEach(all_categories){ i in
Textual content(i.title ?? "")
}
})
// POSIBLE ERROR
}
}
}.padding(.backside)
Button("Submit"){
save_spending()
}
the issues im making an attempt are usually not wokring, assist!