senthil kumar
senthil kumar

Reputation: 91

How do I search multiple values in coredata model?

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

Answers (1)

Tom Harrington
Tom Harrington

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

Related Questions