Skip to content
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

@ViewAction macro does not work if store property is in #if block #3629

Open
3 tasks done
jasin755 opened this issue Mar 19, 2025 · 2 comments
Open
3 tasks done

@ViewAction macro does not work if store property is in #if block #3629

jasin755 opened this issue Mar 19, 2025 · 2 comments
Labels
bug Something isn't working due to a bug in the library.

Comments

@jasin755
Copy link

jasin755 commented Mar 19, 2025

Description

When creating a multiplatform SwiftUI project in Xcode with different deployment targets for macOS and iOS, there is an issue with the @Perception.Bindable macro applied to StoreOf<MyReducer> inside a view.

Problem

On macOS 12.0, @Perception.Bindable is required.
On iOS 17.0, @Perception.Bindable is hard-deprecated and requires @Bindable instead.
This leads to a conflicting requirement that prevents a single universal codebase. One possible workaround is using #if canImport(AppKit):

#if canImport(AppKit)
@Perception.Bindable
private var store: StoreOf<MyReducer>
#else
@Bindable
private var store: StoreOf<MyReducer>
#endif

However, this introduces a secondary issue.

Secondary Issue

When using @ViewAction(for:), it fails to process this conditional property declaration and throws the following error:

@ViewAction requires 'MyView' to have a 'store' property of type 'Store'
This suggests that @ViewAction(for:) does not properly recognize the conditionally defined store property.

Expected Behavior

Composable Architecture should provide a way to:

  • Support both @Perception.Bindable (for older macOS targets) and @Bindable (for newer iOS versions).
  • Ensure @ViewAction(for:) can work correctly in a multiplatform environment.

Composable Architecture Version: 1.18
Xcode Version: 16.2

Any guidance on how to handle this case in a clean and maintainable way would be appreciated.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.
@jasin755 jasin755 added the bug Something isn't working due to a bug in the library. label Mar 19, 2025
@stephencelis stephencelis transferred this issue from pointfreeco/swift-composable-architecture Mar 19, 2025
@stephencelis stephencelis transferred this issue from pointfreeco/swift-perception Mar 19, 2025
@stephencelis
Copy link
Member

@jasin755 Thanks for the report!

I think the behavior of swift-perception makes sense, and so I think this issue is mainly about @ViewAction.

In this case your best bet is to conform to the ViewAction protocol manually to get a synthesized conformance of send. You will sadly lose the linting provided by the macro.

We would also be down to take a PR that adds #if support to the macro if that's something anyone is interested in looking into.

@stephencelis stephencelis changed the title @Perception.Bindable vs. @Bindable Conflict in Multiplatform Projects @ViewAction macro does not work if store property is in #if block Mar 19, 2025
@jasin755
Copy link
Author

@stephencelis PR: #3630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working due to a bug in the library.
Projects
None yet
Development

No branches or pull requests

2 participants