-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Convention for using UniFFI with SwiftUI (Update a SwiftUI view when a UniFFI interface object changes). #2145
Comments
Answered here, to be taken with a huge grain of salt:
|
I think @Sajjon has some interest/knowledge here? |
Hey! There are several dimension to using UniFFI and SwiftUI; let me start by trying to reduce the scope a bit... What is your minimum deployment target? If you can target iOS 17, you can simply write one wrapping model per screen, lets call it ViewModel, which is a class and annotate it with This "solves" your issue completely without any changes needed to UniFFI. If you need to target lower than iOS 17, you can employ the same technique with PointFrees Perception framework. It might be interesting to explore possibilities to in Rust with UniFFI mark a EDIT [clarification]: Even if we (conditionally for iOS/macOS etc) could I don't think we should "blanket mark" all classes with Foremost we don't have any UDL spelling nor proc-macro for binding language specific settings for certain types. It would be very nice to have though! E.g. being able to express mutable/immutable stored properies on certain Swift types, and not catch em all, like we have today. Maybe @mhammond or @bendk can share some thoughts about that specifically... If you are not using/required to use "vanilla SwiftUI" - whatever that means, since there is no clear standard; why I'm a huge fan of opinionated TCA by PointFree too - finally a standard! But I'm digressing... I was gonna say that I've recently managed to POC with TCA and SharedState with UniFFI.. Big PR... TL;DR; my app is completely driven by UniFFI, an object (swift class) for which I have a singleton, lets call it |
Really appreciate all your responses! @Sajjon our minimum deployment is iOS 17 so that's a great solution. Excited to check out TCA and your app I wasn't familiar with TCA. I'll leave the issue open until at least tomorrow to allow members of the UniFFI team to share their thoughts on your suggestions. |
We'd probably prefer to keep things which are language-specific like that in |
SwiftUI uses property wrappers such as @StateObject and @ObservedObject on an ObservableObject (a type of object with a publisher that emits before the object has changed) parameter of a SwiftUI view to update the view whenever the parameter's published properties change (see https://developer.apple.com/documentation/Combine/ObservableObject).
UniFFi issue #2097 discussed that UniFFi does not currently support swift property wrappers but the creator of the issue indicated that there is a convention for using UniFFI with SwiftUI and I was wondering which convention is used to have a SwiftUI view update when a UniFFI interface object changes?
The text was updated successfully, but these errors were encountered: