Skip to content

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

Open
@jasin755

Description

@jasin755

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working due to a bug in the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions