Is there a way to monitor changes to ParseUser.current? I’d like my UI to refresh based on the login status. I’d like to do it through Combine to avoid coupling in the code base as the log out is done through a UIContextMenu which is unaware of the ViewController it is in.
You should be able to accomplish this using a LiveQuery Subscription as its an
ObservableObject which uses Combine. In the case of User.current, you can make a simple query in which `“objectId” == “currentUserObjectId”. There’s an example of how to use LiveQuery in the Playgrounds:
You can find out more about LiveQueries here.
I wasn’t sure what you meant by this part. You can also use the logoutPublisher which also uses
Combine. Anything in ParseSwift that ends in “Publisher” uses Combine.
While a LiveQuery is a solution, it also means one more connection to the server. I’m encapsulating ParseSwift in a class, I’ll try to maintain a @published bool “isLoggedIn” myself then.
I was looking for a way to refresh the UI when the boolean flips, not necessarily when an action is done.
Thanks for the pointers.
Yes, it’s another connection, but a web socket connection. Depending on your server setup, your LiveQuery server may be separate from your ParseServer, so it may or may not be an issue.
If you are using async calls (still another connection) for logout or anything else on your ParseUser, writing your own
@Published properties as you mentioned is probably your best bet as ParseSwift doesn’t offer any other updates to your objects outside of sync, async, publisher (Future-Combine), LiveQuery subscriptions (Combine), and LiveQuery subscriptionCallbacks (Non-Combine). Any other type of offering is developer specific and left to developers to design their own View Models. In addition,
ParseObjects in ParseSwift are intended to be your model in MVVM, so changes to your model should be observed either through LiveQuery Subscriptions (View Model) or your custom View Model, which then notifies your SwiftUI View of changes.