A SwiftUI-like framework for creating cross-platform apps in Swift.
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 perfectly because SwiftCrossUI is intended to be simpler than SwiftUI. However, many concepts from SwiftUI should still be transferrable.
Discussion about SwiftCrossUI now happens in the SwiftCrossUI Discord server (it used to happen in a channel of the SwiftGtk Discord server). Feel free to join if you want to get involved, discuss the library, or just be kept up-to-date on progress!
If you find SwiftCrossUI useful, please consider supporting me by becoming a sponsor. I spend most of my spare time working on open-source projects, and each sponsorship helps me focus more time on making high quality libraries and tools for the community.
Work has been started to support multiple different backends. Switching backends only requires changing a single
line of code! Currently there's the Gtk 4 backend, as well as an experimental AppKit backend (AppKitBackend
, macOS-only). All
examples use GtkBackend
for maximum compatibility, but you can update them manually to try out the various available backends.
Work is being done to allow the backend used by the examples to be changed from the command line.
GtkBackend
: Requires gtk 4 to be installed, has maximum compatibility, and supports all SwiftCrossUI features.AppKitBackend
: Experimental, only supports macOS, and currently supports a very limited subset of SwiftCrossUI features.QtBackend
: Experimental, requires qt5
to be installed, and currently supports a very limited subset of SwiftCrossUI features.Here's a simple example app demonstrate how easy it is to get started with SwiftCrossUI:
import SwiftCrossUI // Import whichever backend you need import GtkBackend class CounterState: Observable { @Observed var count = 0 } @main struct CounterApp: App { // Optionally, you can explicitly select which imported backend to use (this is done for // you if only one backend is imported). // typealias Backend = GtkBackend let identifier = "dev.stackotter.CounterApp" let state = CounterState() var body: some Scene { WindowGroup("CounterApp") { HStack { Button("-") { state.count -= 1 } Text("Count: \(state.count)") Button("+") { state.count += 1 } } .padding(10) } } }
To run this example, run these commands:
git clone https://github.com/stackotter/swift-cross-ui cd swift-cross-ui/Examples swift run CounterExample
A few examples are included with SwiftCrossUI to demonstrate some of its basic features;
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.GreetingGeneratorExample
, a simple app demonstrating dynamic state and the ForEach
view.FileViewerExample
, an app showcasing integration with the system's file chooser.NavigationExample
, an app showcasing NavigationStack
and related concepts.SplitExample
, an app showcasing sidebar-based navigation with multiple levels.StressTestExample
, an app used to test view update performance.SpreadsheetExample
, an app showcasing tables.ControlsExample
, an app showcasing the various types of controls available.All examples use GtkBackend
by default but you can override this using the SCUI_BACKEND
environment variable like so;
SCUI_BACKEND=QtBackend swift run CounterExample
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.
Install Gtk 4 using HomeBrew or the package manager of your choice.
brew install pkg-config gtk4
If you run into errors related to libffi
or FFI
when trying to build a swift-cross-ui project (likely caused by having Xcode CLTs installed), try running the following command to patch libffi:
sed -i '' 's/-I..includedir.//g' $(brew --prefix)/Library/Homebrew/os/mac/pkgconfig/*/libffi.pc
Install Gtk 4 and Clang using apt or the package manager of your choice. On most GNOME-based systems, Gtk should already be installed (although you should verify that it's Gtk 4).
sudo apt install libgtk-4-dev clang
If you run into errors related to not finding gtk/gtk.h
when trying to build a swift-cross-ui project, try restarting your computer. This has worked in some cases (although there may be a more elegant solution).
Installing Gtk 4 using vcpkg is the supported method for setting up SwiftCrossUI on Windows.
git clone https://github.com/microsoft/vcpkg C:\vcpkg C:\vcpkg\bootstrap-vcpkg.bat
NOTE: It's important to install vcpkg to the root of
C:
or any other drive due to limitations of the Gtk build system.
Run the following command to install Gtk 4 globally. This can take 45 minutes or longer depending on your machine. Running this command in the root of your drive will ensure that vcpkg
doesn't run in manifest mode.
C:\vcpkg\vcpkg.exe install gtk --triplet x64-windows
After installation, you must make the following changes to your environment variables:
PKG_CONFIG_PATH
environment variable to C:\vcpkg\installed\x64-windows\lib\pkgconfig
. This is only required for building.C:\vcpkg\installed\x64-windows\bin
to your Path
environment variable. This is only required for running.If installing globally fails, try deleting C:\vcpkg
and starting over, otherwise file an issue to the vcpkg
repository and let me know at stackotter@stackotter.dev
.
NOTE: If the absolute path to your project contains spaces, it is possible that
vcpkg
will break, and installing globally will be a more reliable strategy.
You can install Gtk 4 inside your package workspace, to have a package-specific dependency store. First, create a vcpkg.json
at your package root. You can download the vcpkg.json file from this repo, or create it yourself;
{ "name": "swift-cross-ui", "version-string": "main", "dependencies": ["gtk"] }
Change directory to your package root, then run the following command to build and install dependencies.
C:\vcpkg\vcpkg.exe install --triplet x64-windows
After installation, you must make the following changes to your environment variables:
PKG_CONFIG_PATH
environment variable to PACKAGE_ROOT\vcpkg_installed\x64-windows\lib\pkgconfig
to allow SwiftPM to consume the installed packages.C:\path\to\your\project\vcpkg_installed\x64-windows\bin
to your PATH
environment variable.If you run into issues (potentially related to libsass
), try installing globally instead (see above).
vcpkg_installed\<triplet>\bin
contains all required DLLs for running a SwiftCrossUI application on Windows, but not all of them are necessary.
To identify which of them are required, you can use the Dependencies tool to inspect the compiled executable, and copy all vcpkg-installed DLLs along with the executable for distribution.
# On macOS brew install qt@5 brew link qt@5 # Linux with apt sudo apt install qtcreator qtbase5-dev qt5-qmake cmake
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") ] ) ] )
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命 令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需 求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。
openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。
高分辨率纹理 3D 资产生成
Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。
一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。
3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支 持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。