2

How to convert this objective c code to Swift:

PFQuery *query = [PFQuery queryWithClassName:@"Review"];
[query whereKey:@"comment" notEqualTo:[NSNull null]];

when I simple put:

query.whereKey("comment", notEqualTo: nil)

Xcode throw build error:

'nil' is not compatible with expected argument type 'Any'

Technically I understand that I can't simple put nil there, but I did not found any helpful links with analog [NSNull null]

The method I call looks like this:

- (instancetype)whereKey:(NSString *)key equalTo:(id)object;
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
  • 1
    looks like there is a function called `query.whereKeyDoesNotExist("comment")` that fits my needs but looks like there is no analog in swift for `NSNull null` – Matrosov Oleksandr Sep 08 '21 at 21:07
  • I belive you can still use `NSNull()` in Swift. – Sulthan Sep 08 '21 at 21:15
  • 2
    `[NSNull null]` is not the same as `nil`. `NSNull` is a special singleton object that was used to distinguish between "no object" and a null pointer. As Sulthan says you can use it in Swift, but I would say that the alternate where function you discovered is more elegant – Paulw11 Sep 08 '21 at 21:19

1 Answers1

4

You should be able to use NSNull() directly to represent the NSNull singleton instance.

Sulthan
  • 128,090
  • 22
  • 218
  • 270