A SwiftUI-like framework for creating cross-platform apps in Swift. It uses SwiftGtk as its backend (GTK 4.10+).
This package is still quite a work-in-progress so don't expect it to be very useful or stable yet.
NOTE: SwiftCrossUI does not attempt to replicate SwiftUI's API because SwiftCrossUI is intended to be simpler than SwiftUI. However, many concepts from SwiftUI should still be transferrable.
Example
Here's a simple example app demonstrate how easy it is to get started with SwiftCrossUI:
import SwiftCrossUI
class CounterState: Observable {
@Observed var count = 0
}
@main
struct CounterApp: App {
let identifier = "dev.stackotter.CounterApp"
let state = CounterState()
let windowProperties = WindowProperties(title: "CounterApp")
var body: some ViewContent {
HStack {
Button("-") { state.count -= 1 }
Text("Count: \(state.count)")
Button("+") { state.count += 1 }
}
}
}
To run this example, run these commands:
git clone https://github.com/stackotter/swift-cross-ui
cd swift-cross-ui
swift run CounterExample
To see all of the examples, run these commands:
swift run CounterExample
swift run RandomNumberGeneratorExample
swift run WindowPropertiesExample
swift run GreetingGeneratorExample
swift run FileViewerExample
swift run NavigationExample
Documentation
Here's the documentation site. Keep in mind that the project is still very much a work-in-progress, proper documentation and tutorials will be created once the project has matured a bit, because otherwise I have to spend too much time keeping the documentation up-to-date.
Dependencies
- Swift 5.5 or higher
- Gtk 4.10+
- clang (only required on Linux)
macOS: Installing Gtk 4.10+
Install Gtk 4.10+ using homebrew or the package manager of your choice.
brew install gtk4
Linux: Installing Gtk 4.10+ and clang
Install Gtk+3 and Clang using apt or the package manager of your choice. Ensure that the installed version of Gtk is Gtk 4.10+
sudo apt install libgtk-4-dev clang
Usage
Just add SwiftCrossUI as a dependency in your Package.swift
. See below for an example package manifest:
import PackageDescription
let package = Package(
name: "Example",
dependencies: [
.package(url: "https://github.com/stackotter/swift-cross-ui", .branch("main"))
],
targets: [
.executableTarget(
name: "Example",
dependencies: [
.product(name: "SwiftCrossUI", package: "swift-cross-ui")
]
)
]
)