diff --git a/README.md b/README.md index 90fcf7f460..1fd42419ee 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,11 @@ import SwiftCrossUI import DefaultBackend @main -struct CounterApp: App { +struct YourApp: App { @State var count = 0 var body: some Scene { - WindowGroup("CounterApp") { + WindowGroup("YourApp") { HStack { Button("-") { count -= 1 } Text("Count: \(count)") @@ -80,16 +80,34 @@ struct CounterApp: App { } } ``` +Figure 2: *Sources/YourApp/YourApp.swift* -Clone the SwiftCrossUI repository to test out this example, and many more; +## More examples + +The SwiftCrossUI repository contains the above example and many more. The documentation hosts [a detailed list of all examples](https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui/examples). + +Running the examples requires [Swift Bundler](https://github.com/stackotter/swift-bundler), which provides consistent behavior across platforms and enables running on iOS/tvOS devices and simulators. + +To install Swift Bundler, follow [its official installation instructions](https://github.com/stackotter/swift-bundler?tab=readme-ov-file#installation-). ```sh git clone https://github.com/stackotter/swift-cross-ui cd swift-cross-ui/Examples -swift run CounterExample + +# 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" ``` -The documentation contains [a detailed list of all examples](https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui/examples) +These examples may also be run using SwiftPM. However, resources may not be loaded as expected, and features such as deep linking may not work. You also won't be able to run the examples on iOS or tvOS using this method. + +```sh +# Non-recommended method +swift run CounterExample +``` ## Backends diff --git a/Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md b/Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md index 7e293d6eb3..ab54ea10e2 100644 --- a/Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md +++ b/Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md @@ -9,22 +9,45 @@ A few examples are included with SwiftCrossUI to demonstrate some of its basic f - `CounterExample`, a simple app with buttons to increase and decrease a count. - `RandomNumberGeneratorExample`, a simple app to generate random numbers between a minimum and maximum. - `WindowingExample`, a simple app showcasing how ``WindowGroup`` is used to make multi-window apps and - control the properties of each window. + control the properties of each window. It also demonstrates the use of modals + such as alerts and file pickers. - `GreetingGeneratorExample`, a simple app demonstrating dynamic state and the ``ForEach`` view. - `NavigationExample`, an app showcasing ``NavigationStack`` and related concepts. -- `SplitExample`, an app showcasing sidebar-based navigation with multiple levels. +- `SplitExample`, an app showcasing ``NavigationSplitView``-based hierarchical navigation. - `StressTestExample`, an app used to test view update performance. - `SpreadsheetExample`, an app showcasing tables. - `ControlsExample`, an app showcasing the various types of controls available. +- `NotesExample`, an app showcasing multi-line text editing and a more realistic usage of SwiftCrossUI. +- `PathsExample`, an app showcasing the use of ``Path`` to draw various shapes. +- `WebViewExample`, an app showcasing the use of ``WebView`` to display websites. Only works on Apple platforms so far. -To run an example, either select the example under schemes at the top of the window (in Xcode), or run it from the command line like so: +## Running examples -``` -swift run ExampleToRun +Running the examples requires [Swift Bundler](https://github.com/stackotter/swift-bundler), which provides consistent behavior across platforms and enables running SwiftPM-based apps on iOS/tvOS devices and simulators. + +To install Swift Bundler, follow [its official installation instructions](https://github.com/stackotter/swift-bundler?tab=readme-ov-file#installation-). + +```sh +git clone https://github.com/stackotter/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" ``` If you want to try out an example with a backend other than the default, you can do that too; +```sh +SCUI_DEFAULT_BACKEND=Gtk3Backend swift-bundler run ExampleToRun ``` -SCUI_DEFAULT_BACKEND=QtBackend swift run ExampleToRun + +These examples may also be run using SwiftPM. However, resources may not be loaded as expected, and features such as deep linking may not work. You also won't be able to run the examples on iOS or tvOS using this method. + +```sh +# Non-recommended method +swift run CounterExample ```