Ambiguity of Property wrappers and Macros #2861
Replies: 2 comments 2 replies
-
@DandyLyons You go out of your way of saying that this isn't TCA's fault, but I'd like to go further and point out that this same thing applies to modern SwiftUI: you have a ton of property wrappers ( So I'm not sure TCA can do much when it comes to property wrappers vs. macros other than wait for Apple's vanilla tooling to be better about it. But I also think that ideally a user doesn't have to really think about whether something is a macro or a property wrapper. They can both achieve the same things and the same syntax. In fact, One thing we can do is simplify things in the future, and our internal roadmap aims to simplify the number of
This would mean For example, a reducer without shared state will only see @Reducer
struct Feature {
struct State: Equatable {
var child: Child.State?
}
…
var body: some ReducerOf<Self> {
Reduce { state, action in
…
}
.ifLet(\.child, action: \.child) {
Child()
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Agreed. It really is a language level problem in my opinion. I really wish they chose a different symbol than |
Beta Was this translation helpful? Give feedback.
-
One problem I have with Swift macros is that they look exactly the same as property wrappers at the call site. For example:
@Reducer, @ObservableState, @CasePathable are macros. Whereas
@presents, and @shared are property wrappers.
Both macros and property wrappers write boiler plate code for us but they do so in very different ways, and require us to interact with them differently. For example:
This certainly isn’t TCA’s fault, but I do think it complicates learning TCA, especially for beginners and those transitioning from pre-macro TCA. The user has to create a mental model of which is a macro and which is a property wrapper, and they have to understand the under the hood subtleties of how that effects their call site.
For example, it can be very frustrating to have an entire project fail to compile simply because I forgot to include a
$
symbol. And it's not obvious at the call site why one place needs a$
symbol and the other doesn't. For example:This isn't so much a criticism of TCA, nor a recommendation of something to change. I'm more wondering how we can help in making this mental model easier to learn and retain.
Beta Was this translation helpful? Give feedback.
All reactions