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.
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
What version of the Parse-Server and Swift SDK are you using?
Your bool query is essentially using:
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.
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.
Can you open an issue on the Swift SDK? Iâm guessing this is related to:
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.
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):
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.
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
Your view model is getting kind of long, you may want to setup your view model in an init, like I did here:
I used a similar query here:
The Post model where user is a ParseUser (essentially a Pointer) is here:
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.
Is that new for ParseSwift?
Is there an advantage to doing that?
Is it a security reason?
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
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.
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!
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
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
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.
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?
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).
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.