Start a new topic
Answered

The IN operator

I have a table with a field called "names", which is an array. I would like to use NSPredicate to find all entities which have a certain value within that array.  For example, I may want to find all entities which have "Bob" in names. I have tried


NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K IN names)", @"Bob"];


I get the error: "Can't canonicalize query: BadValue $in needs an array"


Is there a way to do this? I am using iOS SDK 3.3.6.


Best Answer
Michael,

See if this Swift 3 code helps:

let query = Query(format: "names IN %@", “Bob")

   

let _ = dataStore.find(query) { metaData, error in

            print("metaData: \(metaData)")

            

        }


This has worked for me.


Thanks,

Pranav

Kinvey


 

1 Comment

Answer
Michael,

See if this Swift 3 code helps:

let query = Query(format: "names IN %@", “Bob")

   

let _ = dataStore.find(query) { metaData, error in

            print("metaData: \(metaData)")

            

        }


This has worked for me.


Thanks,

Pranav

Kinvey


 

Login or Signup to post a comment