### Run examples with Swift Bundler Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md Clone the repository, navigate to the Examples directory, and run an example on the host machine, a connected device, or a simulator. The --device and --simulator flags are macOS only. ```sh git clone https://github.com/moreSwift/swift-cross-ui cd swift-cross-ui/Examples # Run on host machine swift-bundler run CounterExample # Run on a connected device with "iPhone" in its name (macOS only) swift-bundler run CounterExample --device iPhone # Run on a simulator with "iPhone 16" in its name (macOS only) swift-bundler run CounterExample --simulator "iPhone 16" ``` -------------------------------- ### Run SwiftCrossUI examples with Swift Bundler Source: https://github.com/moreswift/swift-cross-ui/blob/main/README.md Clone the repository and run the CounterExample on the host machine, a connected device, or a simulator. Requires Swift Bundler installed. The --device and --simulator flags are macOS only and support Android devices/emulators as well. ```sh git clone https://github.com/moreSwift/swift-cross-ui cd swift-cross-ui/Examples # Run on host machine swift-bundler run CounterExample # Run on a connected device with "iPhone" in its name (macOS only) # Supports Android devices as well swift-bundler run CounterExample --device iPhone # Run on a simulator with "iPhone 16" in its name (macOS only) # Supports Android emulators as well swift-bundler run CounterExample --simulator "iPhone 16" ``` -------------------------------- ### Run example with a different backend Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md Set the SCUI_DEFAULT_BACKEND environment variable to choose a backend other than the default when running an example with Swift Bundler. ```sh SCUI_DEFAULT_BACKEND=Gtk3Backend swift-bundler run ExampleToRun ``` -------------------------------- ### Install vcpkg on Windows Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Clone and bootstrap vcpkg on Windows. vcpkg must be installed at the root of a drive. ```shell > git clone https://github.com/microsoft/vcpkg C:\vcpkg > C:\vcpkg\bootstrap-vcpkg.bat ``` -------------------------------- ### Run SwiftCrossUI examples with SwiftPM (non-recommended) Source: https://github.com/moreswift/swift-cross-ui/blob/main/README.md Alternative method to run examples using SwiftPM. Resources may not load as expected, deep linking may not work, and iOS/tvOS targets are unsupported. ```sh # Non-recommended method swift run CounterExample ``` -------------------------------- ### Use Gtk3Backend in YourApp.swift Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/Gtk3Backend.md Example SwiftUI app using Gtk3Backend, showing how to import the backend and optionally initialize it with an app identifier. ```swift import SwiftCrossUI import Gtk3Backend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = Gtk3Backend() // // If you aren't using Swift Bundler, you may have to explicitly provide // your app's identifier for some Gtk3Backend features to work correctly // (such as handling custom URL schemes). // // var backend = Gtk3Backend(appIdentifier: "com.example.YourApp") var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### Install Gtk3Backend dependencies on Debian-based distros Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/Gtk3Backend.md Install required system dependencies for Gtk3Backend on Debian-based Linux distributions using apt. ```shell $ sudo apt install libgtk-3-dev clang ``` -------------------------------- ### Install Gtk 4 via Homebrew on macOS Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Install pkg-config and gtk4 using Homebrew on macOS. ```shell $ brew install pkg-config gtk4 ``` -------------------------------- ### SwiftCrossUI example: Package.swift and YourApp.swift Source: https://github.com/moreswift/swift-cross-ui/blob/main/README.md Together these files form the basic SwiftCrossUI example app. Package.swift adds the swift-cross-ui dependency and links the SwiftCrossUI and DefaultBackend products. YourApp.swift creates a @main App with a WindowGroup containing an HStack of decrement and increment buttons and a count label. ```swift import PackageDescription let package = Package( name: "YourApp", dependencies: [ .package( url: "https://github.com/moreSwift/swift-cross-ui", .upToNextMinor(from: "0.2.0") ), ], targets: [ .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "DefaultBackend", package: "swift-cross-ui"), ] ), ] ) ``` ```swift import SwiftCrossUI import DefaultBackend @main struct YourApp: App { @State var count = 0 var body: some Scene { WindowGroup("YourApp") { HStack { Button("-") { count -= 1 } Text("Count: \(count)") Button("+") { count += 1 } }.padding() } } } ``` -------------------------------- ### Install Gtk 4 globally with vcpkg (x64) Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Install Gtk 4 globally for x64 Windows using vcpkg. Run from the root of your drive to avoid manifest mode. ```shell > cd C:\ > C:\vcpkg\vcpkg.exe install gtk --triplet x64-windows ``` -------------------------------- ### Install Gtk3Backend dependencies on Fedora-based distros Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/Gtk3Backend.md Install required system dependencies for Gtk3Backend on Fedora-based Linux distributions using dnf. ```shell $ sudo dnf install gtk3-devel clang ``` -------------------------------- ### Install Windows SDK 10.0.17763 with winget Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/WinUIBackend.md Install the Windows SDK 10.0.17763 required at compile time. If version 17763 fails, try 17736 due to a typo in older Windows versions. ```shell > winget install --id Microsoft.WindowsSDK.10.0.17763 ``` -------------------------------- ### Full documentation comment example Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Example of a documentation comment that follows all the rules: sentence case, punctuation, symbol links, named links, and documentation of parameters, return type, and preconditions. ```swift /// Computes this view's layout after a state change or a change in /// available space. /// /// Implementations of this method should follow similar semantics to the /// [SwiftUI layout algorithm][algorithm]. /// /// The default implementation lives at /// ``View/defaultComputeLayout(_:children:proposedSize:environment:backend:)-(_,any ViewGraphNodeChildren,_,_,_)``. /// /// [algorithm]: https://www.hackingwithswift.com/books/ios-swiftui/how-layout-works-in-swiftui /// /// - Precondition: Requires that the target widget has been added to its parent widget. /// - Parameters: /// - widget: The widget to compute the layout for. /// - children: The view's child nodes. /// - proposedSize: The size suggested by the parent container. /// - environment: The environment to compute the layout in. /// - backend: The backend used to create the widget. /// - Returns: The view's computed layout result. func computeLayout( _ widget: Backend.Widget, children: any ViewGraphNodeChildren, proposedSize: ProposedViewSize, environment: EnvironmentValues, backend: Backend ) -> ViewLayoutResult ``` -------------------------------- ### Good comment examples Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Shows examples of well-formatted comments. Includes a properly formatted single-line comment and a TODO comment with a GitHub username. ```swift // This comment is well formatted // TODO(stackotter): Make this more robust once we have a state dependency // tracking system ``` -------------------------------- ### Install Gtk 4 and clang on Debian-based Linux Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Use apt to install the required Gtk 4 development headers and clang on Debian-based distributions. ```shell $ sudo apt install libgtk-4-dev clang ``` -------------------------------- ### Install Gtk3Backend dependencies on macOS Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/Gtk3Backend.md Install required system dependencies for Gtk3Backend on macOS using Homebrew. ```shell $ brew install pkg-config gtk+3 ``` -------------------------------- ### Install Gtk 4 globally with vcpkg (arm64) Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Install Gtk 4 globally for arm64 Windows using vcpkg. Run from the root of your drive to avoid manifest mode. ```shell > cd C:\ > C:\vcpkg\vcpkg.exe install gtk --triplet arm64-windows ``` -------------------------------- ### Install Gtk 4 and clang on Fedora-based Linux Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Use dnf to install the required Gtk 4 development headers and clang on Fedora-based distributions. ```shell $ sudo dnf install gtk4-devel clang ``` -------------------------------- ### Bad comment examples Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Shows examples of poorly formatted comments to avoid. Includes missing space after double slash, incorrect capitalization, multi-line comment syntax, and TODO without a GitHub username. ```swift //this comment is poorly formatted //This comment is poorly formatted /* This comment uses the multi-line comment syntax, which SwiftCrossUI doesn't use */ // TODO: Fix this todo comment that isn't attributed to a GitHub username ``` -------------------------------- ### Run Gtk3Backend tests with SCUI_TEST_GTK3BACKEND=1 Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Runs Gtk3Backend-specific tests alongside the default tests. These tests are disabled by default because many contributors don't have Gtk 3 installed; CI always runs them. ```sh SCUI_TEST_GTK3BACKEND=1 ./Scripts/test.sh ``` -------------------------------- ### Running with hot reloading: swift-bundler run --hot Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Hot reloading.md Start a hot reloading session with Swift Bundler. The initial build may take longer than a regular incremental build, but subsequent builds should be faster. Swift Bundler currently only observes the app's Sources directory. ```sh swift-bundler run --hot ``` -------------------------------- ### vcpkg.json manifest for Gtk dependency Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Create this vcpkg.json file at the root of your project to declare the gtk dependency for project-local installation. ```json { "name": "project-name", "version-string": "main", "dependencies": ["gtk"] } ``` -------------------------------- ### YourApp.swift: Define app entry point Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/AndroidBackend.md Define the main app struct with an optional backend initialization and a simple WindowGroup scene. ```swift import SwiftCrossUI import AndroidBackend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = AndroidBackend() // // If you want to hook into your Android app's lifecycle methods you can // provide your own ActivityDelegate. // // var backend = AndroidBackend(delegate: MyActivityDelegate()) var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### Preview documentation with preview_docs.sh Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Commands to preview documentation. The first builds SwiftCrossUI to obtain symbol graphs, the second skips symbol graphs for faster previews when working on articles or tutorials. ```sh # Preview docs (builds SwiftCrossUI first to obtain symbol graphs, and then # previews Sources/SwiftCrossUI/SwiftCrossUI.docc) ./Scripts/preview_docs.sh # Preview docs without symbol graphs (faster if just working on articles/tutorials) SKIP_SYMBOL_GRAPHS=1 ./Scripts/preview_docs.sh ``` -------------------------------- ### YourApp.swift: Initialize AppKitBackend and define the app Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/AppKitBackend.md Shows the main app structure using SwiftCrossUI and AppKitBackend. The backend is automatically initialized when importing any built-in backend, but you can explicitly initialize it if desired. ```swift import SwiftCrossUI import AppKitBackend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = AppKitBackend() var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### YourApp.swift: Define app with GtkBackend Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Defines the main app entry point using the GtkBackend. The backend is initialized automatically when importing GtkBackend, but can be explicitly created with GtkBackend() or GtkBackend(appIdentifier:) if needed. ```swift import SwiftCrossUI import GtkBackend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = GtkBackend() // // If you aren't using Swift Bundler, you may have to explicitly provide // your app's identifier for some Gtk3Backend features to work correctly // (such as handling custom URL schemes). // // var backend = GtkBackend(appIdentifier: "com.example.YourApp") var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### Run on Android device or emulator Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/AndroidBackend.md Commands to list devices, run on a device, list emulators, and run on an emulator using Swift Bundler. ```sh # List available Android devices swift-bundler devices list --os android # Run on your device swift-bundler run --device "Your Device" # List available Android emulators swift-bundler simulators list --os android # Run on your emulator swift-bundler run --simulator "Your Simulator" ``` -------------------------------- ### Create a WinUIBackend app in YourApp.swift Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/WinUIBackend.md Define a minimal SwiftCrossUI app using the WinUIBackend. Importing WinUIBackend automatically selects the backend; you can optionally initialize it explicitly. ```swift import SwiftCrossUI import WinUIBackend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = WinUIBackend() var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### Package.swift: Add SwiftCrossUI and GtkBackend dependencies Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Adds SwiftCrossUI and GtkBackend as dependencies for the YourApp executable target in the Package.swift manifest. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "GtkBackend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### YourApp.swift: Use DefaultBackend in your app Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/DefaultBackend.md Imports SwiftCrossUI and DefaultBackend, and defines the main app structure. The backend is automatically initialized when importing any built-in backend; you can optionally explicitly initialize it by uncommenting the 'var backend = DefaultBackend()' line. ```swift import SwiftCrossUI import DefaultBackend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = DefaultBackend() var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### YourApp.swift: Define app with UIKitBackend Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/UIKitBackend.md Defines the main app structure using SwiftCrossUI and UIKitBackend. The backend is automatically selected when importing UIKitBackend, but you can explicitly initialize it or provide a custom UIApplicationDelegate subclass via the alternate initializer. ```swift import SwiftCrossUI import UIKitBackend @main struct YourApp: App { // You can explicitly initialize your app's chosen backend if you desire. // This happens automatically when you import any of the built-in backends. // // var backend = UIKitBackend() // // You can register a custom UIApplicationDelegate by subclassing // UIKitBackend.ApplicationDelegate and providing it to UIKitBackend // via the alternate initializer. // // var backend = UIKitBackend(appDelegateClass: YourAppDelegate.self) var body: some Scene { WindowGroup { Text("Hello, World!") .padding() } } } ``` -------------------------------- ### Package.swift: Add SwiftCrossUI and DefaultBackend dependencies Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/DefaultBackend.md Declares the SwiftCrossUI and DefaultBackend products as dependencies for the executable target named 'YourApp'. This is required to use the DefaultBackend in your app. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "DefaultBackend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### Add Gtk3Backend to Package.swift Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/Gtk3Backend.md Add the Gtk3Backend product as a dependency to your executable target in Package.swift. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "Gtk3Backend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### Package.swift: Add AndroidBackend dependency Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/AndroidBackend.md Add the AndroidBackend product to your executable target's dependencies in Package.swift. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "AndroidBackend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### Run SwiftCrossUI tests with ./Scripts/test.sh Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Runs SwiftCrossUI's tests. The script is required because running `swift test` without arguments builds all backends, including unsupported ones on the current platform. ```sh ./Scripts/test.sh ``` -------------------------------- ### Gesture APIs Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Gestures.md Documentation for gesture-related APIs in SwiftCrossUI, including tap gesture handling and hover detection. ```APIDOC ## View/onTapGesture(gesture:perform:) ### Description Adds a tap gesture handler to a view. The gesture is recognized when the user taps the view, and the perform closure is called with the gesture value. ### Declaration ```swift func onTapGesture(gesture: TapGesture, perform: @escaping (TapGesture.Value) -> Void) -> some View ``` ### Parameters - **gesture** (TapGesture) - Required - The tap gesture to recognize. - **perform** (closure) - Required - The action to perform when the gesture is recognized. Receives the gesture value. ### Return Value A view that triggers the action when the tap gesture is recognized. ``` ```APIDOC ## TapGesture ### Description A gesture that recognizes a tap (a quick touch and release). ### Declaration ```swift struct TapGesture ``` ### Overview Use a `TapGesture` with the `onTapGesture(gesture:perform:)` modifier to handle tap interactions on a view. ``` ```APIDOC ## View/onHover(perform:) ### Description Adds a hover handler to a view. The perform closure is called when the pointer enters or leaves the view. ### Declaration ```swift func onHover(perform: @escaping (Bool) -> Void) -> some View ``` ### Parameters - **perform** (closure) - Required - The action to perform when the hover state changes. Receives a Boolean indicating whether the pointer is hovering over the view. ### Return Value A view that triggers the action when the hover state changes. ``` -------------------------------- ### Package.swift: Add SwiftCrossUI and UIKitBackend dependencies Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/UIKitBackend.md Adds the SwiftCrossUI and UIKitBackend products as dependencies for the executable target named YourApp. This is required to use the UIKitBackend in your app. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "UIKitBackend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### Package.swift: Add SwiftCrossUI and AppKitBackend dependencies Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/AppKitBackend.md Declares the SwiftCrossUI and AppKitBackend products as dependencies for an executable target in a Swift package manifest. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "AppKitBackend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### Fix vcpkg build.ninja dirty error Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Run these commands in Git Bash to fix the 'build.ninja still dirty after 100 tries' error caused by incorrect VM timezone. ```shell $ cd C:\vcpkg $ find . -type f -exec touch {} + ``` -------------------------------- ### Generate SwiftCrossUI swiftinterface file manually Source: https://github.com/moreswift/swift-cross-ui/blob/main/APITool/README.md Command that APITool runs to generate a swiftinterface file for SwiftCrossUI. The resulting file is at .build/debug/SwiftCrossUI.build/SwiftCrossUI.swiftinterface. ```sh swift build --target SwiftCrossUI -Xswiftc -emit-module-interface ``` -------------------------------- ### Diff SwiftCrossUI and SwiftUI with APITool analyze Source: https://github.com/moreswift/swift-cross-ui/blob/main/APITool/README.md Manually run the API diff command. Requires macOS and Xcode. Use --developer-dir to specify a different developer directory than xcode-select --print-path. ```sh # Diff SwiftCrossUI and SwiftUI. If you want to use a developer directory # different to the one reported by 'xcode-select --print-path', then you # specify one using the '--developer-dir' CLI option swift run -c release APITool analyze --scui-checkout .. ``` -------------------------------- ### Instrumenting your app with @HotReloadable and #hotReloadable Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Hot reloading.md Instrument your main app file for hot reloading by importing SwiftBundlerRuntime, annotating the app with @HotReloadable, and wrapping the scene's content with #hotReloadable. The HotReloadable macro must be able to see the hotReloadable usage sites, so the app's body cannot be implemented in an extension. ```swift import DefaultBackend import SwiftCrossUI import SwiftBundlerRuntime // 1. @main @HotReloadable // 2. struct MyApp: App { // ... var body: some Scene { WindowGroup("MyApp") { #hotReloadable { // 3. Text("This is my app!") } } } } ``` -------------------------------- ### Regenerate porting kit generated files with APITool generate Source: https://github.com/moreswift/swift-cross-ui/blob/main/APITool/README.md Manually regenerate the generated files in ../Sources/_SwiftCrossUIPortingKit/Generated. Unlike the script, this does not format the files; run ../Scripts/format.sh on the generated directory to format them. ```sh # Regenerate the porting kit's generated files swift run -c release APITool generate --scui-checkout .. \ ../Sources/_SwiftCrossUIPortingKit/Generated ``` -------------------------------- ### Add WinUIBackend dependency in Package.swift Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/WinUIBackend.md Declare SwiftCrossUI and WinUIBackend as dependencies in your Package.swift manifest for a Windows executable target. ```swift // ... let package = Package( // ... targets: [ // ... .executableTarget( name: "YourApp", dependencies: [ .product(name: "SwiftCrossUI", package: "swift-cross-ui"), .product(name: "WinUIBackend", package: "swift-cross-ui"), ] ), // ... ], // ... ) ``` -------------------------------- ### TODO comment with GitHub username Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Use this format for new TODO comments. The comment must be tagged with your GitHub username, as shown with 'stackotter'. ```swift // TODO(stackotter): Make this more robust once we have a state dependency // tracking system ``` -------------------------------- ### Named link in documentation comment Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Use named links to make documentation markdown line wrap at a sensible width. ```swift /// For a detailed explanation, see Wikipedia's [page on parallel curves][wikipedia]. /// /// [wikipedia]: https://en.wikipedia.org/wiki/Parallel_curve ``` -------------------------------- ### CastBackend macro signature Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/AppBackend refactor.md Use this macro to cast a backend to a more specific protocol inside View method implementations. It simplifies the boilerplate of dynamic casting and currently only works correctly within View methods. ```swift @attached(body) internal macro CastBackend( backendGenericName: String? = nil, returnsWidget: Bool = false ) ``` -------------------------------- ### Symbol link in documentation comment Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Use double backticks to create a symbol link when referring to another symbol within the same target. ```swift /// This method has been superceded by ``View/emphasized()``. ``` -------------------------------- ### Patch libffi on macOS Source: https://github.com/moreswift/swift-cross-ui/blob/main/Sources/SwiftCrossUI/SwiftCrossUI.docc/Backends/GtkBackend.md Run this sed command to patch libffi when encountering libffi or FFI errors on macOS with older Xcode Command Line Tools. ```shell $ sed -i '' 's/-I..includedir.//g' $(brew --prefix)/Library/Homebrew/os/mac/pkgconfig/*/libffi.pc ``` -------------------------------- ### Break function parameters across multiple lines Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Shows the preferred style for breaking function parameters across multiple lines: each parameter on its own line, with the closing parenthesis on its own line at ambient indentation level. The return type is placed on a new line. ```swift func myFunctionWithLotsOfParameters( _ parameter1: Int, _ parameter2: Int, _ parameter3: Int, _ parameter4: Int ) async throws -> MyVeryLongReturnType.Element { // ... } ``` -------------------------------- ### Break long string literals with multiline string and backslash Source: https://github.com/moreswift/swift-cross-ui/blob/main/CONTRIBUTING.md Shows how to break a long string literal across multiple lines using a multiline string literal with backslashes at the end of each line except the last. The message appears as one line to the developer but is line-wrapped in the source file. ```swift log.warning( """ This is a very long warning with lots of context and detail to aid the developer \ in resolving the issue that it's flagging. This message will appear as one line to \ the developer but it line-wrapped within the source file, making things easier to \ read as a SwiftCrossUI contributor. """ ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.