Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse.com: How to properly check if a field is empty?

I ask this in the context of a iOS / Swift app:

When retrieving with a query an object from Parse, I used to check for empty fields by checking them against nil. if != nil.... then do this etc etc....

Apparently, this is not the proper way to do this, because even if a field is empty on Parse, it is NOT considered nil by swift.

So what to to check for to determine if a field is empty or not, and for the various Parse supported types: strings, Number, Array.....?

Edit: there are answers for objective-c that don't work in swift where unless value is a boolean you MUST compare it against nil (which cause issue here) or something else to see if it exists or not.

like image 787
Robert Brax Avatar asked Dec 31 '25 04:12

Robert Brax


1 Answers

You would use whereKeyExists:

Checkout the Parse documentation

If you want to retrieve objects that have a particular key set, you can use whereKeyExists. Conversely, if you want to retrieve objects without a particular key set, you can use whereKeyDoesNotExist.

// Finds objects that have the score set
[query whereKeyExists:@"score"];
like image 162
Kevin Pimentel Avatar answered Jan 01 '26 18:01

Kevin Pimentel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!