Im trying to write a query that looks in a table and only returns results for objectId's that have been stored in an array.
My array column on the backend:
let currentUser = PFUser.current()
let allSelectedPacksArray: NSMutableArray = currentUser?["allSelectedPacks"] as! NSMutableArray
print(allSelectedPacksArray)
Andy query:
let query = PFQuery(className: "Pack")
query.order(byAscending: "packName")
query.whereKey("objectId", containedIn: [allSelectedPacksArray])
query.fromLocalDatastore()
if error != nil || objects?.isEmpty == true {
print("theres no objects to be had")
} else if let items = objects {
objects is empty and console prints:
theres no objects to be had
The print(allSelectedPacksArray) returns the following:
(
tW4qPPdKSp,
HnwTkSwcZc,
zbhe0Kt59Z
)
so the column contains data and it is gettable
when i remove the containedIn line everything works fine. Not sure what I'm doing wrong here. I haven't used NSMutable array much but that seems to be i had to set the array as.
If i don't cast it as NSMutable array like:
let currentUser = PFUser.current()
let allSelectedPacksArray = currentUser?["allSelectedPacks"]
print(allSelectedPacksArray)
the console prints:
Optional(<__NSArrayM 0x60800005a9d0>(
tW4qPPdKSp,
HnwTkSwcZc,
zbhe0Kt59Z
)
)
Thanks for guidance.
The problem here was the use of square brackets around the array.
remove the [] from [allSelectedPacksArray] and just have allSelectedPacksArray and all works.
This is odd because the code prompts for the brackets. but it works.