0
votes

I have an entity called Files with attributes name, id etc. with a toMany relation with other entity called Category having catId.

I am trying to get data which matches Files.catId within an array of ids.

I am writing a predicate as

var idArray: [Int] = [410, 436, 435]
    let catIdPredicate = NSPredicate.init(format: "fileCategory.catId IN %@", idArray)

which is giving me error as Unable to parse the format string "'fileCategory.categoryId' IN ( 410, 436, 435 )

Can anybody tell me how do I write a predicate for the same?

1
Why don't you try NSPredicate(format: "fileCategory.catId IN %@", categoryArray) where categoryArray will be [410, 436, 435] - Shubham Bakshi
I have tried that. Here I have written hardcoded values for better understanding. Will update my question to avoid confusion. - Nilesh
try let predicate = NSPredicate(format: "ANY fileCategory.catId in %@", categoryArray) - iOSer
Cannot reproduce. Your updated code compiles and runs without errors. - Martin R

1 Answers

0
votes

Use ANY in predicate like this:

let idArray: [Int] = [410, 436, 435]
let catIdPredicate = NSPredicate.init(format: "ANY(fileCategory.catId) IN %@", idArray)