Reputation: 91
I have a students entity with attributes { id: String, name: String, age: Int}
I need to fetch the names and age of multiple ids. Can I do it in single fetch or should fetch for each id separately?
Upvotes: 1
Views: 523
Reputation: 70936
You can do it in one fetch. Something like
let ids: [String] = // array of ID values
let predicate = NSPredicate(format: "id in %@", ids)
Use that on the fetch request and it will find all entries which have an ID in the array.
Upvotes: 2