ParseSwift Query to fill a List View

I am porting an Obj-C app over to swift and since it is a bit dated, I have decided to do a complete rewrite. With that I need to fill a SwiftUI List View with the results of a query. Since the data changes slowly it does not seem reasonable to use LiveQuery.

Are there any examples of a simple query of a Parse-Server class where the results are then used to fill a view (not LiveQuery)?

If you are looking for an example, you can look at my ParseCareKitSample project. You will need to follow MVVM just like other SwiftUI projects. For example, using ParseSwift to signup/login users via SwiftUI can be done by setting up the following:

Model - essentially you can think of your ParseSwift objects as your model:

View:

ViewModel - Here isLoggedIn and loginError can use the @Published wrappers instead of the willSet block as I use this to teach my classes how wrappers work:

You can also use anything that ends in Publisher in the documentation.

Since you asked about queries and listing, it’s the same concept as login, just using Query in the documentation. Whenever your data is received in your ViewModel, it should be set equal to your published wrapper, something like @Published var objects: [MyParseObject] which will update the view every time the query is retrieved

An example of creating your own view model has been added to playgrounds:

Swift SDK 1.9.0 makes this easier as it gives you a view model:

If you want to customize the view model, you will either need to subclass QueryViewModel , create your own by conforming to QueryObservable , or create your own from scratch like I mentioned in ParseSwift Query to fill a List View - #2 by cbaker6

This was a great help! Thank you.

One problem though. I adapted this and it performs the query and loads the view, but it keeps requerying the parse server every few seconds. I suspect that it may be reloading based on location changes but have not been able to determine why. Any suggestions?

You can try the official release to see if it helps:

Though this could be happening for any number of reasons. You may be calling something else in your view that continues to publish.

I just released a new app based on SwiftUI and ParseSwift 1.9.0. If you are familiar with the old Parse sample apps/tutorials, SnapCat is similar to AnyPic, but with SwiftUI and ParseSwift. You can look to see how I use the new view models. I so far haven’t run into the issue of re-querying.