-
Notifications
You must be signed in to change notification settings - Fork 230
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
DISCUSS: Proc macro / UDL for Swift property wrappers and macro annotations #2097
Comments
Property wrappers and macro annotations should also accept parameters such that it would be possible to generate this example of the struct NarrowRectangle {
@SmallNumber(wrappedValue: 2, maximum: 5) var height: Int
@SmallNumber(wrappedValue: 3, maximum: 4) var width: Int
} |
Also, I don't see much of a need for UniFFI to define Swift property wrappers or macros—it should only need to apply them. So if you attach e.g. |
That sounds great, but difficult to express in UniFFI's model. Happy to help if you want to have a start at this though. |
@mhammond Thanks! Turns out there's already a convention for writing SwiftUI code with UniFFI, and it's a lot less complicated and more sustainable than this feature would be 😄 Thanks for humoring my whim. Closing as not planned. |
@cadnza What is the convention for writing SwiftUI code with UniFFI with regard to having a view update when a field in a UniFFi Interface / rust struct changes? |
@GraniteLake As far as I understand—first pointing out how wide and varied my lack of experience is with this—the way it's usually done is by writing an intermediary stuct/class in Swift that wraps UniFFI's class and adds SwiftUI's property wrappers and macro annotations. As far as how you get UniFFI to update the struct based on those wrappers and annotations, I'm not sure, but something along those lines is what I've been seeing going through other peoples' code. |
As far as I can tell, UniFFI doesn't have a way to apply property wrappers or macro annotations to types and properties in Swift, so generating this example of the
@ObservedObject
property wrapper using UniFFI is impossible:Generating this example of the
@Observable
macro is also impossible:Property wrappers and macro annotations are used extensively in SwiftUI, so being able to specify them via proc macro or UDL would be wonderful.
To be clear: Property wrappers and macro annotations have uses outside SwiftUI, but SwiftUI is my primary interest.
Two considerations:
Anyway, I'm happy to write the feature if it'd be useful, but first it's worth asking:
The text was updated successfully, but these errors were encountered: