Skip to content

Commit fd6a9a4

Browse files
stackotterVitor Silveira
andauthored
Update example running instructions in readme and docs (with Vitor Silveira) (#199)
* #194: Improve README * #194: Remove overview * #194: Clarify example execution steps and recommend Swift Bundler * Update example running instructions in readme and docs (recommend sbun) --------- Co-authored-by: Vitor Silveira <ext.vitor.silveira@farfetch.com>
1 parent 4b7e3e8 commit fd6a9a4

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ import SwiftCrossUI
6666
import DefaultBackend
6767

6868
@main
69-
struct CounterApp: App {
69+
struct YourApp: App {
7070
@State var count = 0
7171

7272
var body: some Scene {
73-
WindowGroup("CounterApp") {
73+
WindowGroup("YourApp") {
7474
HStack {
7575
Button("-") { count -= 1 }
7676
Text("Count: \(count)")
@@ -80,16 +80,34 @@ struct CounterApp: App {
8080
}
8181
}
8282
```
83+
Figure 2: *Sources/YourApp/YourApp.swift*
8384

84-
Clone the SwiftCrossUI repository to test out this example, and many more;
85+
## More examples
86+
87+
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).
88+
89+
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.
90+
91+
To install Swift Bundler, follow [its official installation instructions](https://github.com/stackotter/swift-bundler?tab=readme-ov-file#installation-).
8592

8693
```sh
8794
git clone https://github.com/stackotter/swift-cross-ui
8895
cd swift-cross-ui/Examples
89-
swift run CounterExample
96+
97+
# Run on host machine
98+
swift-bundler run CounterExample
99+
# Run on a connected device with "iPhone" in its name (macOS only)
100+
swift-bundler run CounterExample --device iPhone
101+
# Run on a simulator with "iPhone 16" in its name (macOS only)
102+
swift-bundler run CounterExample --simulator "iPhone 16"
90103
```
91104

92-
The documentation contains [a detailed list of all examples](https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui/examples)
105+
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.
106+
107+
```sh
108+
# Non-recommended method
109+
swift run CounterExample
110+
```
93111

94112
## Backends
95113

Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,45 @@ A few examples are included with SwiftCrossUI to demonstrate some of its basic f
99
- `CounterExample`, a simple app with buttons to increase and decrease a count.
1010
- `RandomNumberGeneratorExample`, a simple app to generate random numbers between a minimum and maximum.
1111
- `WindowingExample`, a simple app showcasing how ``WindowGroup`` is used to make multi-window apps and
12-
control the properties of each window.
12+
control the properties of each window. It also demonstrates the use of modals
13+
such as alerts and file pickers.
1314
- `GreetingGeneratorExample`, a simple app demonstrating dynamic state and the ``ForEach`` view.
1415
- `NavigationExample`, an app showcasing ``NavigationStack`` and related concepts.
15-
- `SplitExample`, an app showcasing sidebar-based navigation with multiple levels.
16+
- `SplitExample`, an app showcasing ``NavigationSplitView``-based hierarchical navigation.
1617
- `StressTestExample`, an app used to test view update performance.
1718
- `SpreadsheetExample`, an app showcasing tables.
1819
- `ControlsExample`, an app showcasing the various types of controls available.
20+
- `NotesExample`, an app showcasing multi-line text editing and a more realistic usage of SwiftCrossUI.
21+
- `PathsExample`, an app showcasing the use of ``Path`` to draw various shapes.
22+
- `WebViewExample`, an app showcasing the use of ``WebView`` to display websites. Only works on Apple platforms so far.
1923

20-
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:
24+
## Running examples
2125

22-
```
23-
swift run ExampleToRun
26+
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.
27+
28+
To install Swift Bundler, follow [its official installation instructions](https://github.com/stackotter/swift-bundler?tab=readme-ov-file#installation-).
29+
30+
```sh
31+
git clone https://github.com/stackotter/swift-cross-ui
32+
cd swift-cross-ui/Examples
33+
34+
# Run on host machine
35+
swift-bundler run CounterExample
36+
# Run on a connected device with "iPhone" in its name (macOS only)
37+
swift-bundler run CounterExample --device iPhone
38+
# Run on a simulator with "iPhone 16" in its name (macOS only)
39+
swift-bundler run CounterExample --simulator "iPhone 16"
2440
```
2541

2642
If you want to try out an example with a backend other than the default, you can do that too;
2743

44+
```sh
45+
SCUI_DEFAULT_BACKEND=Gtk3Backend swift-bundler run ExampleToRun
2846
```
29-
SCUI_DEFAULT_BACKEND=QtBackend swift run ExampleToRun
47+
48+
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.
49+
50+
```sh
51+
# Non-recommended method
52+
swift run CounterExample
3053
```

0 commit comments

Comments
 (0)