I am learning core data, and I want to add data, before this, i want to check if there is repeated data in Backpack Entity, if there are duplicate values, return Bool to prompt the user. so write this function to get the number of repeated data, but may be the reason for the purple error is not effective, do not know how to solve...
purple error:Accessing StateObject's object without being installed on a View. This will create a new instance each time.
Help please...
func RecheckingEquip() -> Bool {
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Backpack.creatTime, ascending: false)],
predicate: NSPredicate(format: "equipedImage == %@", equips.imageName),
animation: .default) var backpackItems: FetchedResults<Backpack>
let number = backpackItems.count
if number == 0 {
return false
}
return true
}