### Presenting a Settings Sheet in UIKit Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md A basic example of presenting a sheet from a button press in UIKit using a standard UIAction. ```swift let button = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in present(SettingsViewController(), animated: true) }) ``` -------------------------------- ### Observing Model Changes and Updating DOM in Wasm Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md An example for Wasm environments demonstrating how to use the observe function to update the DOM based on model changes. ```javascript import JavaScriptKit var countLabel = document.createElement("span") _ = document.body.appendChild(countLabel) let token = observe { countLabel.innerText = .string("Count: "model.count)") } ``` -------------------------------- ### Drive Navigation from State with Alerts Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Articles/CrossPlatform.md Control navigation flow based on application state, such as presenting an alert when an error occurs. This example shows how to bind an alert to a boolean state variable. ```swift alert(isPresented: $model.isShowingErrorAlert) { "Something went wrong" } ``` -------------------------------- ### Getting the value Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/UIBinding.md Methods for accessing the current value of a UIBinding, including direct access and dynamic member lookups. ```APIDOC ## Accessing UIBinding Values ### Description Methods for retrieving the current value held by a `UIBinding`. ### Methods - `wrappedValue` - `projectedValue` - `subscript(dynamicMember:) ### Properties #### `wrappedValue` - Returns the wrapped value of the binding. #### `projectedValue` - Returns the projected value of the binding. ### Subscripts #### `subscript(dynamicMember:)` - **dynamicMember**: The key path to access a nested property. - Returns the value of the specified dynamic member. ``` -------------------------------- ### UIKit/UIColorWell Initialization and Binding Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIColorWell.md Demonstrates how to initialize a UIColorWell and bind its selected color to observable state. ```APIDOC ## UIKit/UIColorWell ### Description Provides documentation for the `UIColorWell` class from UIKit, focusing on its initialization and how to bind its selected color to observable state. ### Topics #### Binding to observable state - `init(frame:selectedColor:)` - `bind(selectedColor:)` ### Initializer #### `init(frame:selectedColor:)` Initializes a `UIColorWell` with a specified frame and an initial selected color. ### Method #### `bind(selectedColor:)` Binds the `selectedColor` property of the `UIColorWell` to an observable state. This allows for two-way binding between the UI element and your application's state management. **Parameters:** - `selectedColor`: A binding to the `UIColor` that represents the currently selected color. ``` -------------------------------- ### Creating Buttons Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/ButtonState.md Initializers for creating ButtonState instances with different configurations. ```APIDOC ## Initializers for ButtonState ### `init(role:action:label:)` Initializes a new ButtonState with a specified role, action, and label. ### `init(role:action:label:)` Another initializer for ButtonState, potentially with different default behaviors or parameter interpretations. ``` -------------------------------- ### UIBindable Initializers Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/UIBindable.md Provides various initializers for creating UIBindable instances. ```APIDOC ## Initializers for UIBindable ### Description Provides various initializers for creating UIBindable instances, including those that accept a closure, a wrapped value, and source location information. ### Initializers - `init(_:fileID:filePath:line:column:)` - `init(_:fileID:filePath:line:column:)` - `init(wrappedValue:fileID:filePath:line:column:)` - `init(wrappedValue:fileID:filePath:line:column:)` - `init(projectedValue:)` ``` -------------------------------- ### Creating Dialogs Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/ConfirmationDialogState.md Initializers for creating instances of ConfirmationDialogState. ```APIDOC ## Initializers ### `init(title:actions:message:)` Creates a new confirmation dialog state with a title, actions, and an optional message. ### `init(titleVisibility:title:actions:message:)` Creates a new confirmation dialog state with explicit control over title visibility, along with title, actions, and an optional message. ``` -------------------------------- ### AlertState Initialization Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/AlertState.md Initializes a new AlertState with a title, optional actions, and an optional message. ```APIDOC ## init(title:actions:message:) ### Description Initializes a new `AlertState` with a title, optional actions, and an optional message. ### Parameters #### Initializer Parameters - **title** (String) - Required - The title of the alert. - **actions** (Array) - Optional - An array of actions for the alert. - **message** (String?) - Optional - The message content of the alert. ``` -------------------------------- ### Creating TextState Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/TextState.md Provides initializers for creating TextState instances. ```APIDOC ## Creating TextState ### Description Provides initializers for creating `TextState` instances. ### Initializers - `init(_:)` - `init(_:tableName:bundle:comment:)` - `init(verbatim:)` ``` -------------------------------- ### Creating a binding Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/UIBinding.md Provides methods for creating new UIBinding instances, including direct value initialization and binding from other sources. ```APIDOC ## Initializers for UIBinding ### Description Methods for creating and initializing `UIBinding` instances. ### Methods - `init(wrappedValue:) - `init(_:) - `init(constant:) - `init(projectedValue:) - `init(_:fileID:filePath:line:column:) ### Parameters #### `init(wrappedValue:)` - **wrappedValue**: The initial value to wrap in the binding. #### `init(_:)` - **binding**: An existing binding to create a new binding from. #### `init(constant:)` - **constant**: A constant value to create a binding from. #### `init(projectedValue:)` - **projectedValue**: The projected value to initialize the binding with. #### `init(_:fileID:filePath:line:column:)` - **binding**: The binding to initialize from. - **fileID**: The file ID where the initialization occurs. - **filePath**: The file path where the initialization occurs. - **line**: The line number where the initialization occurs. - **column**: The column number where the initialization occurs. ``` -------------------------------- ### present(item:onDismiss:content:)-4x5io Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Presents a view controller modally based on an optional item. ```APIDOC ## present(item:onDismiss:content:)-4x5io ### Description Presents a view controller modally when `item` is not nil. The `onDismiss` closure is called when the presented view controller is dismissed. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### UISwitch Initialization with Binding Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UISwitch.md Initializes a UISwitch with a frame and binds its 'isOn' state to an observable boolean. This allows the switch's state to be controlled and observed externally. ```APIDOC ## init(frame:isOn:) ### Description Initializes a `UISwitch` with a specified frame and binds its `isOn` state to an observable boolean value. Changes to the observable will update the switch, and user interactions with the switch will update the observable. ### Method `init` ### Parameters #### Path Parameters - **frame** (CGRect) - Required - The initial frame for the switch. - **isOn** (Observable) - Required - An observable boolean that the switch's state will be bound to. ### Response #### Success Response (200) Initializes and returns a `UISwitch` instance. ``` -------------------------------- ### Driving UIKit Navigation with State Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Demonstrates how to use UIKitNavigation library tools within a UIViewController to manage navigation based on the FeatureModel's destination state. ```swift import UIKitNavigation class FeatureViewController: UIViewController { @UIBindable var model: FeatureModel func viewDidLoad() { super.viewDidLoad() // Set up view hierarchy present(item: $model.destination.addItem) { addItemModel in AddItemViewController(model: addItemModel) } present(isPresented: UIBinding($model.destination.deleteItemAlert)) { let alert = UIAlertController(title: "Delete?", message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Yes", style: .destructive)) alert.addAction(UIAlertAction(title: "No", style: .cancel)) return alert } navigationDestination(item: $model.destination.editItem) { editItemModel in EditItemViewController(model: editItemModel) } } } ``` -------------------------------- ### Presenting a Sheet with UIButton Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/UIKitNavigation.md Standard UIKit approach to present a sheet from a button press. This is a 'fire-and-forget' method. ```swift let button = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in present(SettingsViewController(), animated: true) }) ``` -------------------------------- ### push(value:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Pushes a new view controller onto the navigation stack. ```APIDOC ## push(value:) ### Description Pushes a new view controller onto the navigation stack. The `value` parameter represents the data or view model associated with the new screen. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Driving Alert Navigation in Wasm Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Shows how to drive navigation, specifically an alert, from state in a Wasm environment using the provided library functions. ```swift alert(isPresented: $model.isShowingErrorAlert) { "Something went wrong" } ``` -------------------------------- ### Initializing UIStepper with a Value Binding Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIStepper.md Initializes a UIStepper with a frame and a binding to observable state. This allows the stepper's value to be controlled and observed externally. ```APIDOC ## init(frame:value:) ### Description Initializes a `UIStepper` instance with a specified frame and a binding to an observable state. ### Parameters - **frame** (CGRect) - The initial frame for the stepper. - **value** (Binding) - A binding to a `Double` value that controls the stepper's state. ``` -------------------------------- ### present(isPresented:onDismiss:content:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Presents a view controller modally based on a binding. ```APIDOC ## present(isPresented:onDismiss:content:) ### Description Presents a view controller modally when `isPresented` is true. The `onDismiss` closure is called when the presented view controller is dismissed. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### present(item:onDismiss:content:)-4m7m3 Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Presents a view controller modally based on an optional item. ```APIDOC ## present(item:onDismiss:content:)-4m7m3 ### Description Presents a view controller modally when `item` is not nil. The `onDismiss` closure is called when the presented view controller is dismissed. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Optional State for Navigation Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/SwiftUINavigation.md Demonstrates the traditional approach using multiple optionals to manage different navigation states. This can lead to invalid states where multiple navigation types are active simultaneously. ```swift @Observable class FeatureModel { var addItem: AddItemModel? var deleteItemAlertIsPresented: Bool var editItem: EditItemModel? // ... } ``` ```swift .sheet(item: $model.addItem) { addItemModel in AddItemView(model: addItemModel) } .alert("Delete?", isPresented: $model.deleteItemAlertIsPresented) { Button("Yes", role: .destructive) { /* ... */ } Button("No", role: .cancel) {} } .navigationDestination(item: $model.editItem) { editItemModel in EditItemModel(model: editItemModel) } ``` -------------------------------- ### Add Swift Navigation to Package.swift Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Add Swift Navigation as a package dependency in your SwiftPM project's Package.swift file. ```swift dependencies: [ .package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.0.0") ] ``` -------------------------------- ### navigationDestination(for:destination:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Configures a navigation destination for a specific type. ```APIDOC ## navigationDestination(for:destination:) ### Description Configures a navigation destination for a given data type. When an item of the specified `for` type is encountered, the `destination` closure is used to create the view to navigate to. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### present(item:id:onDismiss:content:)-4xafn Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Presents a view controller modally based on an optional item and an identifier. ```APIDOC ## present(item:id:onDismiss:content:)-4xafn ### Description Presents a view controller modally when `item` is not nil. The `onDismiss` closure is called when the presented view controller is dismissed. An `id` can be used for identification. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### present(item:id:onDismiss:content:)-9fu88 Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Presents a view controller modally based on an optional item and an identifier. ```APIDOC ## present(item:id:onDismiss:content:)-9fu88 ### Description Presents a view controller modally when `item` is not nil. The `onDismiss` closure is called when the presented view controller is dismissed. An `id` can be used for identification. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### NavigationStackController Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Represents a controller for stack-based navigation. ```APIDOC ## NavigationStackController ### Description Represents a controller specifically designed for managing stack-based navigation. This is a fundamental component for implementing navigation where views are pushed onto and popped from a stack. ### Method Not applicable (SDK component) ### Endpoint Not applicable (SDK component) ### Parameters None ### Request Example None ### Response None ### Response Example None ``` -------------------------------- ### UISlider Initialization with Value Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UISlider.md Initializes a UISlider with a specified frame and an initial value, preparing it for binding to observable state. ```APIDOC ## init(frame:value:) ### Description Initializes a UISlider with a specified frame and an initial value. ### Parameters #### Path Parameters - **frame** (CGRect) - The frame for the slider. - **value** (Binding) - The observable binding for the slider's value. ### Method - init ``` -------------------------------- ### TextState Transformations Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/TextState.md Details how TextState can be transformed into SwiftUI Text and Swift String. ```APIDOC ## TextState Transformations ### Description Details how `TextState` can be transformed into `SwiftUI/Text` and `Swift/String`. ### Transformations - `SwiftUI/Text` - `Swift/String` ``` -------------------------------- ### FeatureModel with Optional State Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Initial model using separate optionals for different navigation destinations. This approach can lead to invalid states where multiple destinations are active simultaneously. ```swift @Observable class FeatureModel { var addItem: AddItemModel? var deleteItemAlertIsPresented: Bool var editItem: EditItemModel? } ``` -------------------------------- ### Configuring Animations Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIKitAnimation.md Provides methods to configure animation properties such as delay, repeat count, and speed. ```APIDOC ## delay(_:) ### Description Configures the delay before the animation starts. ### Method Modifier ### Endpoint N/A (Swift API) ### Parameters - **delay** (Double) - Required - The delay in seconds. ### Response - `Animation`: The animation with the configured delay. ## repeatCount(_:autoreverses:) ### Description Configures the number of times the animation should repeat and whether it should autoreverse. ### Method Modifier ### Endpoint N/A (Swift API) ### Parameters - **repeatCount** (Int) - Required - The number of repetitions. - **autoreverses** (Bool) - Required - Whether the animation should autoreverse. ### Response - `Animation`: The animation with the configured repeat count and autoreverse behavior. ## repeatForever(autoreverses:) ### Description Configures the animation to repeat indefinitely and whether it should autoreverse. ### Method Modifier ### Endpoint N/A (Swift API) ### Parameters - **autoreverses** (Bool) - Required - Whether the animation should autoreverse. ### Response - `Animation`: The animation configured to repeat forever. ## speed(_:) ### Description Configures the speed of the animation. ### Method Modifier ### Endpoint N/A (Swift API) ### Parameters - **speed** (Double) - Required - The speed multiplier for the animation. ### Response - `Animation`: The animation with the configured speed. ``` -------------------------------- ### AlertState Properties Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/AlertState.md Provides access to the data stored within an AlertState instance. ```APIDOC ## AlertState Properties ### Description These properties allow you to read the data associated with an `AlertState`. ### Properties - **id** (UUID) - A unique identifier for the alert state. - **title** (String) - The title of the alert. - **message** (String?) - The message content of the alert. - **buttons** (Array) - An array of actions available for the alert. ``` -------------------------------- ### navigationDestination(isPresented:content:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Configures a navigation destination based on a binding. ```APIDOC ## navigationDestination(isPresented:content:) ### Description Configures a navigation destination that is presented when `isPresented` is true. The `content` closure provides the view to navigate to. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Presenting a Fullscreen Cover with Enum State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/SheetsPopoversCovers.md For fullscreen covers driven by enum state, use the `fullscreenCover(item:id:content:)` overload with a case path to present the cover from a specific enum case. ```swift struct ContentView: View { @State var destination: Destination? @CasePathable enum Destination { case counter(Int) // More destinations } var body: some View { List { // ... } .fullscreenCover(item: $destination.counter, id: \.self) { $number in CounterView(number: $number) } } } ``` -------------------------------- ### navigationDestination(item:content:)-1gks3 Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Configures a navigation destination based on an optional item. ```APIDOC ## navigationDestination(item:content:)-1gks3 ### Description Configures a navigation destination that is presented when `item` is not nil. The `content` closure provides the view to navigate to. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Transforming Dialogs Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/ConfirmationDialogState.md Methods for transforming a ConfirmationDialogState instance. ```APIDOC ## Methods ### `map(_:)` Transforms the dialog state by applying a closure to its content. This method is generic and works with any type that conforms to `SwiftUI.Visibility`. #### Parameters - `transform`: A closure that takes the current dialog content and returns a transformed content. ``` -------------------------------- ### Handling Alert Actions Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Implement an endpoint to handle user interactions with the alert, performing specific logic based on the tapped button's action. ```swift func alertButtonTapped(_ action: AlertAction?) { switch action { case .confirmDelete: // NB: Perform deletion logic here case nil: // NB: Perform cancel button logic here } } ``` -------------------------------- ### destination(isPresented:content:present:dismiss:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Defines a custom tree-based navigation destination. ```APIDOC ## destination(isPresented:content:present:dismiss:) ### Description Defines a custom tree-based navigation destination that is presented when `isPresented` is true. It takes closures for presenting and dismissing the destination. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Default Animation Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/AppKitNavigation/Documentation.docc/Extensions/AppKitAnimation.md Retrieves the default animation configuration. ```APIDOC ## default ### Description Retrieves the default animation configuration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Response #### Success Response - **animation** (AnimationType) - The default animation object. ``` -------------------------------- ### Binding UIPageControl's Current Page Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIPageControl.md Provides an initializer for UIPageControl that accepts a frame and an initial current page, and a method to bind the current page to an observable state. ```APIDOC ## `UIKit/UIPageControl` ### Topics #### Binding to observable state - `UIKit/UIPageControl/init(frame:currentPage:)` - `UIKit/UIPageControl/bind(currentPage:)` ``` -------------------------------- ### destination(item:content:present:dismiss:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Defines a custom tree-based navigation destination based on an optional item. ```APIDOC ## destination(item:content:present:dismiss:) ### Description Defines a custom tree-based navigation destination that is presented when `item` is not nil. It takes closures for presenting and dismissing the destination. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### navigationDestination(item:content:)-5auro Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Configures a navigation destination based on an optional item. ```APIDOC ## navigationDestination(item:content:)-5auro ### Description Configures a navigation destination that is presented when `item` is not nil. The `content` closure provides the view to navigate to. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Transforming Buttons Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/ButtonState.md Methods for transforming ButtonState instances. ```APIDOC ## Transforming Buttons ### `map(_:)` Transforms the ButtonState by applying a closure to its components. ``` -------------------------------- ### Managing changes Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/UIBinding.md Provides functionalities for managing changes to a UIBinding, including identification and transaction handling. ```APIDOC ## Managing UIBinding Changes ### Description Provides tools for managing and observing changes within a `UIBinding`. ### Properties #### `id` - Returns a unique identifier for the binding. #### `transaction` - Returns the current transaction associated with the binding. ### Methods #### `transaction(_:)` - **transaction**: The transaction to apply to the binding. - Applies a transaction to the binding, managing changes within its scope. ``` -------------------------------- ### Custom Animations Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIKitAnimation.md Provides methods for creating custom animations, including duration-based, spring-based, and initializer-based animations. ```APIDOC ## animate(withDuration:delay:options:) ### Description Creates a custom animation with specified duration, delay, and options. ### Method Initializer ### Endpoint N/A (Swift API) ### Parameters - **withDuration** (Double) - Required - The duration of the animation. - **delay** (Double) - Required - The delay before the animation starts. - **options** (AnimationOptions) - Required - The animation options. ### Response - `Animation`: A custom animation. ## animate(withDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:) ### Description Creates a custom spring animation with detailed spring physics parameters. ### Method Initializer ### Endpoint N/A (Swift API) ### Parameters - **withDuration** (Double) - Required - The duration of the animation. - **delay** (Double) - Required - The delay before the animation starts. - **usingSpringWithDamping** (Double) - Required - The spring damping ratio. - **initialSpringVelocity** (Double) - Required - The initial velocity of the spring. - **options** (AnimationOptions) - Required - The animation options. ### Response - `Animation`: A custom spring animation. ## animate(springDuration:bounce:initialSpringVelocity:delay:options:) ### Description Creates a custom spring animation using a simplified spring configuration. ### Method Initializer ### Endpoint N/A (Swift API) ### Parameters - **springDuration** (Double) - Required - The duration of the spring animation. - **bounce** (Double) - Required - The bounce factor of the spring. - **initialSpringVelocity** (Double) - Required - The initial velocity of the spring. - **delay** (Double) - Required - The delay before the animation starts. - **options** (AnimationOptions) - Required - The animation options. ### Response - `Animation`: A custom spring animation. ## init(_:) ### Description Initializes an animation with a provided `Animation` instance. ### Method Initializer ### Endpoint N/A (Swift API) ### Parameters - **animation** (Animation) - Required - The animation instance to initialize with. ### Response - `Animation`: An animation instance. ``` -------------------------------- ### Conditional Button Logic in Alert Actions Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Demonstrates using the actions closure as a result builder to conditionally include buttons based on item state. ```swift } actions: { if item.isLocked { ButtonState(role: .destructive, action: .confirmDelete) { TextState("Unlock and delete") } } else { ButtonState(role: .destructive, action: .confirmDelete) { TextState("Delete") } } ButtonState(role: .cancel) { TextState("Nevermind") } } ``` -------------------------------- ### SwiftUI View with Bindable Focus State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/Bindings.md This SwiftUI view integrates with the SignInModel, using @FocusState for managing focus and the .bind modifier to synchronize the view's focus with the model's focus state. ```swift struct SignInView: View { @FocusState var focus: SignInModel.Field? @ObservedObject var model: SignInModel var body: some View { Form { TextField("Email", text: self.$model.email) .focused(self.$focus, equals: .email) TextField("Password", text: self.$model.password) .focused(self.$focus, equals: .password) Button("Sign in") { Task { await self.model.signInButtonTapped() } } } // ⬇️ Replays changes of `model.focus` to `focus` and vice-versa. .bind(self.$model.focus, to: self.$focus) } } ``` -------------------------------- ### observe(isolation:_:)-9xf99 Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/Observe.md Attaches data to observation with specified isolation. ```APIDOC ## observe(isolation:_:)-9xf99 ### Description Attaches data to observation with specified isolation. ### Topics #### Attaching data to observation - ``observe(isolation:_:)-34d7t`` ``` -------------------------------- ### Linear Animations Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/AppKitNavigation/Documentation.docc/Extensions/AppKitAnimation.md Provides options for creating linear animations, with or without a specified duration. ```APIDOC ## linear ### Description Creates a linear animation with the default duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Response #### Success Response - **animation** (AnimationType) - A linear animation object. ``` ```APIDOC ## linear(duration:) ### Description Creates a linear animation with a specified duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Parameters #### Query Parameters - **duration** (TimeInterval) - Required - The duration of the animation in seconds. ``` -------------------------------- ### destination(item:id:content:present:dismiss:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIViewController.md Defines a custom tree-based navigation destination based on an optional item and an identifier. ```APIDOC ## destination(item:id:content:present:dismiss:) ### Description Defines a custom tree-based navigation destination that is presented when `item` is not nil. It takes closures for presenting and dismissing the destination. An `id` can be used for identification. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Observable Class for Sign-In State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/Bindings.md This observable class stores sign-in credentials and focus state. It handles the API sign-in logic and updates the focus to the email field upon failure. ```swift @Observable class SignInModel { var email: String var password: String var focus: Field? enum Field { case email, password } func signInButtonTapped() async throws { do { try await self.apiClient.signIn(self.email, self.password) } catch { self.focus = .email } } } ``` -------------------------------- ### Presenting an Alert with Buttons and Message Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Update the alert state with a title, message, and buttons to display a confirmation dialog to the user. TextState is used for equatable text. ```swift func deleteButtonTapped() { self.alert = AlertState { TextState("Are you sure?") } actions: { ButtonState(role: .destructive, action: .confirmDelete) { TextState("Delete") } ButtonState(role: .cancel) { TextState("Nevermind") } } message: { TextState("Deleting this item cannot be undone.") } } ``` -------------------------------- ### Observe Model Changes and Update DOM in Wasm Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Articles/CrossPlatform.md Use the `observe` function to react to changes in a Swift model and update the Document Object Model (DOM) in a WebAssembly environment. This requires the JavaScriptKit import. ```swift import JavaScriptKit var countLabel = document.createElement("span") _ = document.body.appendChild(countLabel) let token = observe { countLabel.innerText = .string("Count: \(model.count)") } ``` -------------------------------- ### Testing Alert State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Verify alert presentation and user interaction by asserting against the equatable AlertState properties. This enables robust testing of alert logic. ```swift func testDelete() { let model = FeatureModel(/* ... */) model.deleteButtonTapped() XCTAssertEqual(model.alert?.title, TextState("Are you sure?")) model.alertButtonTapped(.confirmDelete) // NB: Assert that deletion actually occurred. } ``` -------------------------------- ### Performing Actions Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/ButtonState.md Methods to modify or associate actions with a ButtonState. ```APIDOC ## Performing Actions ### `withAction(_:)` Attaches or modifies the action associated with the button state. ### `withAction(_:)` An alternative method for associating actions with the button state. ``` -------------------------------- ### Observing Model Changes for UI Updates Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/UIKitNavigation.md Uses the `observe` tool to automatically track model property accesses and update the UI accordingly. The trailing closure is invoked whenever tracked properties change, ensuring the UI reflects the latest data. ```swift observe { [weak self] in guard let self else { return } countLabel.text = "Count: \(model.count)" factLabel.isHidden = model.fact == nil if let fact = model.fact { factLabel.text = fact } activityIndicator.isHidden = !model.isLoadingFact } ``` -------------------------------- ### NavigationLink with Enum State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/Navigation.md Use the NavigationLink initializer with an optional enum destination to specify which case drives navigation. The action closure hydrates the state, and the destination closure provides the binding to the unwrapped state. ```swift NavigationLink(item: $destination.counter) { isActive in destination = isActive ? .counter(42) : nil } destination: { $number in CounterView(number: $number) } label: { Text("Go to counter") } ``` -------------------------------- ### Custom Animations Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/AppKitNavigation/Documentation.docc/Extensions/AppKitAnimation.md Allows for the creation of custom animations with specific durations and timing functions, or by providing a custom timing function directly. ```APIDOC ## animate(duration:timingFunction:) ### Description Creates a custom animation with a specified duration and timing function. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Parameters #### Query Parameters - **duration** (TimeInterval) - Required - The duration of the animation in seconds. - **timingFunction** (TimingFunction) - Required - The timing function to use for the animation. ``` ```APIDOC ## init(_:) ### Description Initializes an animation with a custom timing function. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Parameters #### Query Parameters - **timingFunction** (TimingFunction) - Required - The custom timing function to use for the animation. ``` -------------------------------- ### AlertState Transformation Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/AlertState.md Transforms the AlertState using a provided mapping function. ```APIDOC ## map(_:) ### Description Transforms the `AlertState` by applying a mapping function to its content. ### Parameters #### Method Parameters - **transform** ((String) -> String) - Required - A function that transforms the alert's title and message. ``` -------------------------------- ### Presenting a Fullscreen Cover with Optional State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/SheetsPopoversCovers.md Fullscreen covers can be presented from optional state using the `fullscreenCover(item:id:content:)` modifier, which provides a binding to the unwrapped value. ```swift struct ContentView: View { @State var destination: Int? var body: some View { List { // ... } .fullscreenCover(item: $destination, id: \.self) { $number in CounterView(number: $number) } } } ``` -------------------------------- ### Binding UIStepper to Observable State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIStepper.md Provides a method to bind the UIStepper's value to an observable state. This is useful for two-way data binding scenarios. ```APIDOC ## bind(value:) ### Description Binds the `UIStepper`'s current value to an observable `Binding`. ### Parameters - **value** (Binding) - The binding to the observable state that will be updated when the stepper's value changes, and vice-versa. ``` -------------------------------- ### Define Confirmation Dialog State Model Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Model for a delete confirmation dialog, including actions and message. Use this to define the structure and behavior of your confirmation dialogs. ```swift @Observable class FeatureModel { var dialog: ConfirmationDialogState? enum DialogAction { case confirmDelete } func deleteButtonTapped() { dialog = ConfirmationDialogState(titleVisibility: .visible) { TextState("Are you sure?") } actions: { ButtonState(role: .destructive, action: .confirmDelete) { TextState("Delete") } ButtonState(role: .cancel) { TextState("Nevermind") } } message: { TextState("Deleting this item cannot be undone.") } } func dialogButtonTapped(_ action: DialogAction?) { switch action { case .confirmDelete: // NB: Perform deletion logic here case nil: // NB: Perform cancel button logic here } } } ``` -------------------------------- ### AlertState Model for Deletion Confirmation Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Define an optional AlertState and an enum for alert actions within your observable model to manage alert presentation and user interactions. ```swift @Observable class FeatureModel { var alert: AlertState? enum AlertAction { case confirmDelete } // ... } ``` -------------------------------- ### Presenting a Popover with Enum State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/SheetsPopoversCovers.md When using a case-pathable enum for popover destinations, utilize the `popover(item:id:content:)` overload with a case path to present the popover from a specific enum case. ```swift struct ContentView: View { @State var destination: Destination? @CasePathable enum Destination { case counter(Int) // More destinations } var body: some View { List { // ... } .popover(item: $destination.counter, id: \.self) { $number in CounterView(number: $number) } } } ``` -------------------------------- ### Presenting a Sheet with Enum State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/SheetsPopoversCovers.md For mutually exclusive destinations, model state as a case-pathable enum. Use the `sheet(item:id:content:)` overload with a case path to present a sheet from a specific enum case. ```swift @State var destination: Destination? @CasePathable enum Destination { case counter(Int) // More destinations } var body: some View { List { // ... } .sheet(item: $destination.counter, id: \.self) { $number in CounterView(number: $number) } } ``` -------------------------------- ### Binding UISwitch to Observable State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UISwitch.md Provides a method to bind the 'isOn' state of a UISwitch to an observable boolean. This is useful for two-way data binding between the UI element and your application's state. ```APIDOC ## bind(isOn:) ### Description Binds the `isOn` state of the `UISwitch` to an observable boolean. This establishes a two-way binding, meaning changes to the observable will update the switch, and user interactions with the switch will update the observable. ### Method `bind` ### Parameters #### Path Parameters - **isOn** (Observable) - Required - An observable boolean value to bind the switch's state to. ### Response #### Success Response (200) Returns the `UISwitch` instance after binding the state. ``` -------------------------------- ### Driving Navigation in a View Controller Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/UIKitNavigation.md Utilizes UIKitNavigation tools within a UIViewController to manage navigation based on the state of a @UIBindable model. Navigation is triggered when the model's destination becomes non-nil and the model is updated when a presented view is dismissed. ```swift class FeatureViewController: UIViewController { @UIBindable var model: FeatureModel func viewDidLoad() { super.viewDidLoad() // Set up view hierarchy present(item: $model.destination.addItem) { addItemModel in AddItemViewController(model: addItemModel) } present(isPresented: Binding($model.destination.deleteItemAlert)) { let alert = UIAlertController(title: "Delete?", message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Yes", style: .destructive)) alert.addAction(UIAlertAction(title: "No", style: .cancel)) return alert } navigationDestination(item: $model.destination.editItem) { editItemModel in EditItemViewController(model: editItemModel) } } } ``` -------------------------------- ### Feature Model with Navigation Destinations Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Defines a feature model with an enum for navigation destinations, supporting various states like adding an item, showing an alert, or editing an item. ```swift import SwiftNavigation @Observable class FeatureModel { var destination: Destination? @CasePathable enum Destination { case addItem(AddItemModel) case deleteItemAlert case editItem(EditItemModel) } } ``` -------------------------------- ### Present Confirmation Dialog in SwiftUI View Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Integrate the confirmation dialog state into a SwiftUI view using the .confirmationDialog modifier. This allows the view to present the dialog based on the model's state. ```swift struct ContentView: View { @ObservedObject var model: FeatureModel var body: some View { List { // ... } .confirmationDialog($model.dialog) { dialogButtonTapped(action) } } } ``` -------------------------------- ### Binding to observable text Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UITextField.md Provides initializers and a method to bind the text of a UITextField to an observable text property. ```APIDOC ## `init(frame:text:)` ### Description Initializes a UITextField with a frame and a binding to an observable text property. ### Method `init` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None ## `bind(text:)` ### Description Binds the text of a UITextField to an observable text property. ### Method `bind` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None ``` -------------------------------- ### Presenting Alerts via CasePathable Destination Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/AlertsDialogs.md Use an alternative .alert view modifier that accepts a case path to specify which case of the destination enum drives the alert presentation. ```swift .alert($model.destination.alert) { model.alertButtonTapped(action) } ``` -------------------------------- ### Presenting a Sheet with Optional State Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/SheetsPopoversCovers.md Use the `sheet(item:)` overload to present a sheet when a piece of optional state is non-nil. The trailing closure receives a binding to the unwrapped state. ```swift struct ContentView: View { @State var destination: Int? // ... } var body: some View { List { // ... } .sheet(item: $destination) { $number in CounterView(number: $number) } } ``` -------------------------------- ### Eased Animations Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/AppKitNavigation/Documentation.docc/Extensions/AppKitAnimation.md Offers various eased animation types, including ease-in, ease-out, and ease-in-out, with optional duration. ```APIDOC ## easeIn ### Description Creates an ease-in animation with the default duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Response #### Success Response - **animation** (AnimationType) - An ease-in animation object. ``` ```APIDOC ## easeIn(duration:) ### Description Creates an ease-in animation with a specified duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Parameters #### Query Parameters - **duration** (TimeInterval) - Required - The duration of the animation in seconds. ``` ```APIDOC ## easeOut ### Description Creates an ease-out animation with the default duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Response #### Success Response - **animation** (AnimationType) - An ease-out animation object. ``` ```APIDOC ## easeOut(duration:) ### Description Creates an ease-out animation with a specified duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Parameters #### Query Parameters - **duration** (TimeInterval) - Required - The duration of the animation in seconds. ``` ```APIDOC ## easeInOut ### Description Creates an ease-in-out animation with the default duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Response #### Success Response - **animation** (AnimationType) - An ease-in-out animation object. ``` ```APIDOC ## easeInOut(duration:) ### Description Creates an ease-in-out animation with a specified duration. ### Method GET (Implicit) ### Endpoint N/A (Property access) ### Parameters #### Query Parameters - **duration** (TimeInterval) - Required - The duration of the animation in seconds. ``` -------------------------------- ### bind(_:to:for:) Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Documentation.docc/Extensions/UIControlProtocol.md Binds a UIControl to an observable state for a specific event. Changes in the observable state update the control, and user interactions with the control update the observable state. ```APIDOC ## bind(_:to:for:) ### Description Binds a UIControl to an observable state for a specific event. This provides a one-way binding where changes to the observable state will update the control's value. ### Method UIControl.bind(_:to:for:) ### Parameters #### Path Parameters - **control** (UIControl) - The UI control to bind. - **state** (Observable) - The observable state to bind to. - **event** (UIControl.Event) - The control event that triggers the update of the observable state. ``` -------------------------------- ### Reading Dialog Data Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftNavigation/Documentation.docc/Extensions/ConfirmationDialogState.md Properties available for accessing data from a ConfirmationDialogState instance. ```APIDOC ## Properties ### `id` A unique identifier for the dialog state. ### `title` The title of the confirmation dialog. ### `titleVisibility` Controls the visibility of the dialog's title. ### `message` The optional message content of the dialog. ### `buttons` An array of actions (buttons) available in the dialog. ``` -------------------------------- ### Enum State for Navigation Source: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/SwiftUINavigation/Documentation.docc/Articles/Navigation.md Model navigation destinations as an enum when a feature can navigate to multiple, mutually exclusive screens. Apply the @CasePathable macro for dynamic case lookup. ```swift @CasePathable enum Destination { case counter(Int) case text(String) } ``` ```swift @State var destination: Destination? ``` -------------------------------- ### Observing Model Changes for UI Updates in UIKit Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Utilizes the 'observe' function from UIKitNavigation to automatically update UI elements when specific properties of an observable model change. ```swift observe { [weak self] in guard let self else { return } countLabel.text = "Count: "model.count)" factLabel.isHidden = model.fact == nil if let fact = model.fact { factLabel.text = fact } activityIndicator.isHidden = !model.isLoadingFact } ``` -------------------------------- ### SwiftUI Navigation Modifiers with Optional State Source: https://github.com/pointfreeco/swift-navigation/blob/main/README.md Using SwiftUI's built-in modifiers (.sheet, .alert, .navigationDestination) with optional state. This demonstrates the direct mapping of optional properties to navigation presentations. ```swift .sheet(item: $model.addItem) { addItemModel in AddItemView(model: addItemModel) } .alert("Delete?", isPresented: $model.deleteItemAlertIsPresented) { Button("Yes", role: .destructive) { /* ... */ } Button("No", role: .cancel) {} } .navigationDestination(item: $model.editItem) { editItemModel in EditItemModel(model: editItemModel) } ```