Skip to content

Update example running instructions in readme and docs (with Vitor Silveira) #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand All @@ -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

Expand Down
35 changes: 29 additions & 6 deletions Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Loading