Skip to content

Use Property wrappers on the @ObservableState properties #2938

Answered by mbrandonw
hadiidbouk asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @hadiidbouk, this is just an issue with Swift macros in general, in particular ones that turn a stored property into a stored+computed property duo. This affects Apple's own @Observable and @Model macros too.

There really is no universal, good solution to this problem. All I can say is that we are currently running a shared state beta right now that solves the particular problem you are having, that of backing a field with user defaults. You will be able to use it like so:

@Shared(.appStorage("isDebugModeEnabled")) var isDebugModeEnabled: Bool

So, you can either give the beta a spin now, or wait until the tools officially ship sometime in the near future.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hadiidbouk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants