You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-31Lines changed: 15 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,11 @@ import SwiftCrossUI
66
66
importDefaultBackend
67
67
68
68
@main
69
-
structCounterApp: App {
69
+
structYourApp: App {
70
70
@Statevar count =0
71
71
72
72
var body: some Scene {
73
-
WindowGroup("CounterApp") {
73
+
WindowGroup("YourApp") {
74
74
HStack {
75
75
Button("-") { count -=1 }
76
76
Text("Count: \(count)")
@@ -80,51 +80,35 @@ struct CounterApp: App {
80
80
}
81
81
}
82
82
```
83
+
Figure 2: *Sources/YourApp/YourApp.swift*
83
84
84
-
Clone the SwiftCrossUI repository to test out this example and others. Running the examples requires an installation of [Swift Bundler](https://github.com/stackotter/swift-bundler), which provides consistent behavior across platforms and enables running on iOS and tvOS simulators and devices.
85
+
## More examples
85
86
86
-
To install Swift Bundler, you can follow [its official installation instructions](https://github.com/stackotter/swift-bundler?tab=readme-ov-file#installation-). Swift Bundler is typically installed using [Mint](https://github.com/yonaskolb/Mint?tab=readme-ov-file#installing), a Swift package manager that lets you easily install and run CLI tools distributed as Swift packages.
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).
87
88
88
-
If you don't have Mint installed, you can install it with [Homebrew](https://brew.sh/):
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.
89
90
90
-
```sh
91
-
brew install mint
92
-
```
93
-
94
-
Then use Mint to install Swift Bundler:
95
-
96
-
```sh
97
-
mint install stackotter/swift-bundler@main
98
-
```
99
-
100
-
Once installed, clone the project and run the example:
91
+
To install Swift Bundler, follow [its official installation instructions](https://github.com/stackotter/swift-bundler?tab=readme-ov-file#installation-).
# On a connected device with "iPhone" in its name (macOS only)
112
-
swift bundler run CounterExample device iPhone
113
96
114
-
# On a simulator with "iPhone 16" in its name (macOS only)
115
-
swift bundler run CounterExample simulator "iPhone 16"
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"
116
103
```
117
104
118
-
These examples may also be run on your host machine without Swift Bundler by using SwiftPM:
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.
119
106
120
107
```sh
108
+
# Non-recommended method
121
109
swift run CounterExample
122
110
```
123
111
124
-
However, resources may not be loaded as expected, and features like deep linking may not work. This method also does not support running on iOS or tvOS.
125
-
126
-
The documentation contains [a detailed list of all examples](https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui/examples)
127
-
128
112
## Backends
129
113
130
114
SwiftCrossUI has a variety of backends tailored to different operating systems. The beauty of SwiftCrossUI is that you can write your app once and have it look native everywhere. For this reason I recommend using [DefaultBackend](https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui/defaultbackend) unless you've got particular constraints.
Copy file name to clipboardExpand all lines: Sources/SwiftCrossUI/SwiftCrossUI.docc/Examples.md
+29-6Lines changed: 29 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,22 +9,45 @@ A few examples are included with SwiftCrossUI to demonstrate some of its basic f
9
9
-`CounterExample`, a simple app with buttons to increase and decrease a count.
10
10
-`RandomNumberGeneratorExample`, a simple app to generate random numbers between a minimum and maximum.
11
11
-`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.
13
14
-`GreetingGeneratorExample`, a simple app demonstrating dynamic state and the ``ForEach`` view.
14
15
-`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.
16
17
-`StressTestExample`, an app used to test view update performance.
17
18
-`SpreadsheetExample`, an app showcasing tables.
18
19
-`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.
19
23
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
21
25
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-).
# 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"
24
40
```
25
41
26
42
If you want to try out an example with a backend other than the default, you can do that too;
27
43
44
+
```sh
45
+
SCUI_DEFAULT_BACKEND=Gtk3Backend swift-bundler run ExampleToRun
28
46
```
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.
0 commit comments