Reputation: 73
hi i'm not really understanding how the fetch filter works can anyone help me please? So i currently have this as my fetchall function which displays all of my items within my entity
im having trouble of filtering only one attribute which is a boolean. I want it to only display attributes that are true.
thankyou!
func fetchAllItems(){
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "AllItems")
do{
let result = try managedObjectContext.fetch(request)
beastList = result as! [AllItems]
} catch { print("\(error)")
}
}
Upvotes: 0
Views: 1107
Reputation: 17725
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "AllItems")
request.predicate = NSPredicate(format: "something = %@", argumentArray: [true])
Note: Replace something
with your boolean field name
let request : NSFetchRequest<AllItems> = AllItems.fetchRequest()
It is better to name your entity in singular form, so that each row in your entity could be in singular form.
AllItems
seems very generic, if you are storing cars, the entity name could be Car
. The variable that stores the result of the fetch request could be cars
.
Upvotes: 2