Reputation: 6556
I need to make a query from my application in swift. I'm using cloudKit so, I can't use the SQL language.
I wanna write an instruction that is similar to :
SELECT *
FROM parola
WHERE IDParola IN ("1","4","5","10"); //And so on with numbers
I have read that in swift i have to use the NSPredicate, so I write:
var predicate = NSPredicate(format: "IDParola IN { "1", "2" }")
let query = CKQuery(recordType: "Parola", predicate: predicate)
But This code give me the error: "Terminating app due to uncaught exception 'CKException', reason: 'Unexpected expression: IDParola IN {1, 2}' *** First throw call stack..."
I read this page: https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKQuery_class/index.html , I tried without the ", I tried in all ways (I think), but it doesn't work. It only works if I write:
var predicate = NSPredicate(format: "IDParola = 1")
let query = CKQuery(recordType: "Parola", predicate: predicate)
But with this code I retrive only one record... Who can help me? Thank you first!!
Upvotes: 0
Views: 566
Reputation: 10479
You can try this:
var predicate = NSPredicate(format: "IDParola IN %@", [1, 2])
let query = CKQuery(recordType: "Parola", predicate: predicate)
Upvotes: 2