Overview
The@Presents macro is used to mark properties that represent optional child feature state in tree-based navigation. It wraps the property with PresentationState and provides observation support when used with the @ObservableState macro.
Use this macro instead of the @PresentationState property wrapper when adopting the @ObservableState macro, which is incompatible with property wrappers.
Declaration
Usage
Basic Presentation
Use@Presents to mark optional child state in your feature’s state:
Multiple Destinations with Enum
When supporting multiple presentation destinations, use@Presents with an enum:
Accessing Presented State
The macro provides a projected value (with$ prefix) of type PresentationState:
Key Points
- Observation Support: Automatically integrates with SwiftUI’s observation system when used with
@ObservableState - Projected Value: Provides a
$prefixed projected value of typePresentationState - Navigation Integration: Works seamlessly with the
ifLetreducer operator for tree-based navigation - Type Safety: Ensures compile-time safety for optional child state management
Related Types
PresentationState- The underlying property wrapper typePresentationAction- Action wrapper for presented features@ObservableState- Macro for observable state conformanceifLet- Reducer operator for optional state