# ParseSwift Query Question

**URL:** <https://community.parseplatform.org/t/parseswift-query-question/2180>\
**Category:** ParseSwift SDK\
**Created:** [November 15, 2021, 9:50pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180 "2021-11-15T21:50:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 15, 2021, 9:50pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/1 "2021-11-15T21:50:02Z")

</div>

Hello,

Would someone here be able to show me, or point me, to a sample to query for a user? I have a collection that has a column with a user pointer. I am able to create queries for strings, int, etc. But I am unclear as to the syntax for finding a record that matches a user pointer.

U. hope this makes sense, I have used ParseiOS for a long time and am familiar, but I am new to SwiftUI and ParseSwift. There are not many samples and not much doc so I am struggling with it a bit.

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 15, 2021, 11:22pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/2 "2021-11-15T23:22:42Z")

</div>

The playgrounds is the best place for examples:

> **[Parse-Swift/ParseSwift.playground/Pages at main · parse-community/Parse-Swift](https://github.com/parse-community/Parse-Swift/tree/main/ParseSwift.playground/Pages)**
>
> The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows) - parse-community/Parse-Swift

In terms of querying for pointers, querying on the User class is the same as any other Parse class:

> <https://github.com/parse-community/Parse-Swift/blob/25b70d9a7c939c05a8fe86abfe375ebcba081e75/ParseSwift.playground/Pages/8%20-%20Pointers.xcplaygroundpage/Contents.swift#L162-L213>

If you want to use async/await, just use `try await` instead of `try` when querying. More on async/await here:

> [@Async / await with ParseSwift Query sample?](https://community.parseplatform.org/t/async-await-with-parseswift-query-sample/2099/3):
>
> The Swift SDK playgrounds(completion handler) and [test cases](https://github.com/parse-community/Parse-Swift/tree/main/Tests/ParseSwiftTests)(completion handler and async/await) provide a number of examples. From the test cases, a completion handler query cane be done: The async/await version looks like (there’s also a [Combine version](https://github.com/parse-community/Parse-Swift/blob/2bda2fd4a98ce923d1dce5a9f90fd964357cdb00/Tests/ParseSwiftTests/ParseQueryCombineTests.swift#L96-L113)): In terms of simple MVVM with SwiftUI (my first post shows how to do a more sophisticated one), the Swift SDK provides a number of items out-of-the-box. The assumptions are: Model (ParseObject) ViewModel (Query/LiveQuerySubscription/Cl…

A complete app showing how to use the Swift SDK in SwiftUI is here:

> [@Async / await with ParseSwift Query sample?](https://community.parseplatform.org/t/async-await-with-parseswift-query-sample/2099/2):
>
> A sample repo I created, [SnapCat](https://github.com/netreconlab/SnapCat), shows off a lot of the Parse Swift SDK capabilities such as: SwiftUI compatibility (Models & ViewModels), LiveQuery, async/await, etc. For comparison, you can look at the iOS14 branch which only uses completion handlers. A fetch example is below (query and everything else is very similar): The same code written using async/await is below: There are tons of examples how to use the SDK with MVVM and SwiftUI. To highlight a one I think is super useful, is cr…

96% of the SDK is documented: [ParseSwift Reference](http://parseplatform.org/Parse-Swift/api/)

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 16, 2021, 4:35pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/3 "2021-11-16T16:35:46Z")

</div>

Ok, yes, SnapCat was very helpful, I got qeuries working, but I do have one thing I do not understand.

I can do this: Word.query(WordKey.word == “Some Text”) and it works (string compare)  
I can so this: Word.query(WordKey.wordOrder \< 8) and it works (int)  
But this does not: Word.query(WordKey.isWordNeeded == true) Bool fields do not seem to work, it always return a 0 result set

Is there something special with a bool that I am missing? SnapCat does not query on bools anywhere and the doc part showing comparison functions does not having anything special for bools

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 16, 2021, 4:52pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/4 "2021-11-16T16:52:52Z")

</div>

What version of the Parse-Server and Swift SDK are you using?

Your bool query is essentially using:

> <https://github.com/parse-community/Parse-Swift/blob/a121bde14587491bf8797d32ede43ac6e049979f/Sources/ParseSwift/Types/Query.swift#L114-L122>

Which should work. It’s possible the server isn’t like how this is being encoded in JSON. Or, the server can have a bug, but this seems like a simple query that should be covered in the server tests.

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 16, 2021, 4:56pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/5 "2021-11-16T16:56:21Z")

</div>

I think Parse-Server is the latest and my project is Swift 5 Xcode 13.1

Ok, so I checked my code and it seems correct, I will verify which Parse-Server version I am running, but I agree this should be covered as it is pretty basic.

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 16, 2021, 5:13pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/6 "2021-11-16T17:13:44Z")

</div>

Can you open an issue on the Swift SDK? I’m guessing this is related to:

> <https://github.com/parse-community/Parse-Swift/pull/49>
>
> \`==\` was originally using \`$eq\` which works with Parse-Server, but isn't listed …in the REST documentation. The problem is that the LiveQuery server doesn't use \`$eq\`, so this fix makes the SDK encode \`==\` in a way that's compatible with both the Parse Server and LiveQuery server.
> \- \[x\] Fix related test cases.

Basically, $eq was removed because of the way LiveQuery used it. It’s possible $eq is needed for regular queries and can’t leverage the same way LiveQuery uses it. If this is the case, it’s problematic as the server should choose a specific way or handle both cases.

@davimacedo @dplewis @Manuel if my guess is correct, this is also related to my comments on:

> <https://github.com/parse-community/parse-server/pull/7227#discussion_r611092794>
>
> Just supporting what @davimacedo mentioned about \`$eq\` not working for LiveQuery… is true. @dplewis if you recall, I was using \`$eq\` in ParseSwift and asked you about it here https://github.com/parse-community/parse-server/pull/7113#issuecomment-758064363. I then made a change to ParseSwift to not use \`$eq\` anymore here https://github.com/parse-community/Parse-Swift/pull/49

Also related to:

> <https://github.com/parse-community/parse-server/pull/7607>
>
> \### New Pull Request Checklist
> \<!--
> Please check the following boxes \[x\] b…efore submitting your issue.
> Click the "Preview" tab for better readability.
> Thanks for contributing to Parse Server!
> \--\>
> 
> \- \[x\] I am not disclosing a \[vulnerability\](https://github.com/parse-community/parse-server/blob/master/SECURITY.md).
> \- \[x\] I am creating this PR in reference to an \[issue\](https://github.com/parse-community/parse-server/issues/7606).
> 
> \### Issue Description
> 
> As per this \[issue\](https://github.com/parse-community/Parse-SDK-JS/issues/1372), currently it is not possible to combine \`equalTo\` clause with any other clauses and vice-versa using Parse-SDK-JS. After adding support for combining \`equalTo\` clause with other clauses in \[Parse-SDK-JS's pr.\](https://github.com/parse-community/Parse-SDK-JS/pull/1373)
> 
> We need to add support \`equalTo\` for LiveQuery, so that it triggers correct events for client.
> 
> Related issue: #7606
> 
> \### Approach
> 
> 
> add support for $eq query in \[LiveQuery's matchKeyConstraints\](https://github.com/parse-community/parse-server/blob/20cb3333aba67fb89e4e2cda586c559bdb4a23ef/src/LiveQuery/QueryTools.js#L148).
> 
> \### TODOs before merging
> \<!--
> Add TODOs that need to be completed before merging this PR.
> Delete suggested TODOs that do not apply to this PR.
> \--\>
> 
> \- \[x\] Add test cases

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 16, 2021, 5:19pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/7 "2021-11-16T17:19:55Z")

</div>

Hmmm, ok, I will post the same thing I posted here on the Swift SDK and see where it goes.

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 16, 2021, 5:24pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/8 "2021-11-16T17:24:30Z")

</div>

Ok, posted here: [Bool query not working... · Issue #282 · parse-community/Parse-Swift · GitHub](https://github.com/parse-community/Parse-Swift/issues/282)

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 16, 2021, 7:57pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/9 "2021-11-16T19:57:04Z")

</div>

I think this is a false alarm. I checked a bool query in Swift Playgrounds and it works fine as is.

@LilMoke I recommend you check your code and parse dashboard for mistakes. You can test the example I used in Swift Playgrounds here (directions in the README about how to use docker to get a test server up and running in seconds):

> <https://github.com/parse-community/Parse-Swift/blob/e0aa6652243f612391be1096fcbfa8262124ca4d/ParseSwift.playground/Pages/2%20-%20Finding%20Objects.xcplaygroundpage/Contents.swift#L76-L92>

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 16, 2021, 8:02pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/10 "2021-11-16T20:02:25Z")

</div>

Hmmmm, ok, I will check it out, thank you for looking further! It could very well be me, a lot of new things for me with SwiftUI and ParseSwift… lol

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 17, 2021, 2:56am UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/11 "2021-11-17T02:56:09Z")

</div>

cbaker6, so sorry on the bool, it was my fault, cs101 mistake, but I do have one more question.

I am doing this:

```
@ObservedObject var wordsWordViewModel = Word.query(WordKey.isActiveButton == true,
												WordKey.cgsUser == User.current)
	.includeAll()
	.order([.ascending(WordKey.buttonOrder)])
	.viewModel

```

The WordKey.cgsUser is a pointer to a user in the User collection. If I remove that line the bool works, I fixed that issue, but now when I add the pointer to user so I can pull only the records for that user, it does not match. I added .includeAll so it would include the User collection.

What am I doing wrong with this one?

However, on a good note, I have a better understanding of it now, so hopefully the pointer matches are my last crazy questions.

Thanks for the help!!

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 17, 2021, 11:44am UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/12 "2021-11-17T11:44:31Z")

</div>

There needs to be a `try?` as the `Query` will fail `User.current` can’t be converted to a `Pointer`, or you can convert `User.current` to a pointer before using it in a query, [Functions Reference](http://parseplatform.org/Parse-Swift/api/Functions.html#/s:10ParseSwift2eeoiyAA15QueryConstraintVSS_xtKAA0A6ObjectRzlF)

Your view model is getting kind of long, you may want to setup your view model in an init, like I did here:

> <https://github.com/netreconlab/SnapCat/blob/f8fdcc0e039ea8ff62f9f0884804f8ee90575a0b/SnapCat/Home/TimeLineView.swift#L79-L98>

I used a similar query here:

> <https://github.com/netreconlab/SnapCat/blob/f8fdcc0e039ea8ff62f9f0884804f8ee90575a0b/SnapCat/Home/TimeLineViewModel.swift#L50>

The `Post` model where `user` is a `ParseUser` (essentially a `Pointer`) is here:

> <https://github.com/netreconlab/SnapCat/blob/f8fdcc0e039ea8ff62f9f0884804f8ee90575a0b/SnapCat/Models/Post.swift#L19>

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 18, 2021, 1:15pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/13 "2021-11-18T13:15:45Z")

</div>

cbaker6, can you briefly explain to me why in SnapCat you set the default calc for all parse objects? I have been using Parse for several UIKit apps over the past few years and have never had to do that.

1. Is that new for ParseSwift?
2. Is there an advantage to doing that?
3. Is it a security reason?
4. Is there some feature SnapCat has that requires you to do that?

Thank you, BTW, your help above has helped me with loading pointer objects. Lol, I am starting to become a SnapCat lover and expert

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 18, 2021, 1:56pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/14 "2021-11-18T13:56:36Z")

</div>

> [@LilMoke](#):
>
> can you briefly explain to me why in SnapCat you set the default calc for all parse objects? I have been using Parse for several UIKit apps over the past few years and have never had to do that.

Are you referring to the `defaultACL`? If so, I believe a few of the SDK’s have this, particularly the Obj-C SDK, [iOS Developers Guide | Parse](https://docs.parseplatform.org/ios/guide/#access-control-lists).

> To make it super easy to create user-private ACLs for every object, we have a way to set a default ACL that will be used for every new object you create

This is useful if you are creating ParseObject classes from the client side. Many developers use Cloud Code to manage ACL’s and CLP’s; you can also use the Parse Dashboard. In SnapCat, this is done on each ParseObject, because the defaultACL currently isn’t set to the object before a save. I may add this if I get some time later this week.

> Thank you, BTW, your help above has helped me with loading pointer objects. Lol, I am starting to become a SnapCat lover and expert

This is great to hear! I’m glad SnapCat is useful. If you find any bugs, feel free to open a PR!

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 18, 2021, 3:33pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/15 "2021-11-18T15:33:20Z")

</div>

Why do some places you use QueryViewModel and other places, for example, you use TimeLineViewModel, etc. Why do you need QueryViewModel? And, likewise, why can’t you always use classes like TimeLineViewModel… if the question makes sense.

Is it because QueryViewModel is a ParseObject? It seems like TimeLineViewModel and others can be QueryViewModels

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 18, 2021, 3:38pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/16 "2021-11-18T15:38:28Z")

</div>

Oh wait, I am sorry, I see it know, QueryViewModel us part of ParseSwift. And things like TimeLineViewmodel are your own View Model Classes. And QueryViewModel has some useuful comments with explanation

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 18, 2021, 3:53pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/17 "2021-11-18T15:53:40Z")

</div>

> [@LilMoke](#):
>
> QueryViewModel has some useuful comments with explanation

Yes, those comments make up the documentation here: [QueryViewModel Class Reference](http://parseplatform.org/Parse-Swift/api/Classes/QueryViewModel.html)

To see how to combine a standard query with live query to make a powerful view model that reactively responds to changes on the server, you can look at `QueryImageViewModel` which subclasses `Subscription` → `QueryViewModel`. This is used whenever you see the property `subscribeCustom`.

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 18, 2021, 3:59pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/18 "2021-11-18T15:59:58Z")

</div>

Ahhh ok, yes, I did see that. Thank you. So why does your ProfileView user QueryViewModel and your ActivityView uses ActivityViewModel. Couldn’t ProfileView just use a ProfileViewModel and all the queries required live there? I guess I don’t get why the ProfileView need QueryViewModel?

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 18, 2021, 4:37pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/19 "2021-11-18T16:37:02Z")

</div>

It matters what you need for your views. In my case, I’m tying multiple view models to ProfileView (and other views). Some of the view models are simple and can use the Swift SDK stock view model, others are more complicated. Sometimes I want my view models to be reactive using LiveQuery, other times the views can just use standard queries. In the end, it’s about your use-cases and how you choose to design using MVVM (or variations of it).

---

<div class="post-metadata">

**Author:** ![LilMoke](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lilmoke/32/855_2.png) [@LilMoke](https://community.parseplatform.org/u/LilMoke)\
**Post date:** [November 18, 2021, 4:40pm UTC](https://community.parseplatform.org/t/parseswift-query-question/2180/20 "2021-11-18T16:40:41Z")

</div>

Ok, that is exactly what I was thinking but I was not sure. It was good to here you validate what I was thinking. That was how it appeared, but I was not entirely sure.

[Next page](https://community.parseplatform.org/t/parseswift-query-question/2180.md?page=2)
