{"id":13872260,"url":"https://github.com/rhx/SwiftGtk","last_synced_at":"2025-07-16T02:30:30.175Z","repository":{"id":43809629,"uuid":"60699564","full_name":"rhx/SwiftGtk","owner":"rhx","description":"A Swift wrapper around gtk-3.x and gtk-4.x that is largely auto-generated from gobject-introspection","archived":false,"fork":false,"pushed_at":"2024-06-15T07:10:51.000Z","size":76992,"stargazers_count":317,"open_issues_count":5,"forks_count":26,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-06-15T10:59:38.988Z","etag":null,"topics":["gnome","gobject-introspection","gtk","gtk3","gtk4","linux","macos","swift","swift-wrapper"],"latest_commit_sha":null,"homepage":"https://rhx.github.io/SwiftGtk/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-08T13:23:23.000Z","updated_at":"2024-08-06T00:34:29.400Z","dependencies_parsed_at":"2024-01-23T07:25:34.461Z","dependency_job_id":"d0f2e5f5-507d-4aa5-b133-d1a3fa0ea83c","html_url":"https://github.com/rhx/SwiftGtk","commit_stats":{"total_commits":296,"total_committers":8,"mean_commits":37.0,"dds":"0.15202702702702697","last_synced_commit":"a2d345d92a66c942f494f9d6f60a372054c23824"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhx%2FSwiftGtk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhx%2FSwiftGtk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhx%2FSwiftGtk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhx%2FSwiftGtk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhx","download_url":"https://codeload.github.com/rhx/SwiftGtk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225759734,"owners_count":17519851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gnome","gobject-introspection","gtk","gtk3","gtk4","linux","macos","swift","swift-wrapper"],"created_at":"2024-08-05T23:00:38.152Z","updated_at":"2024-11-23T20:30:50.486Z","avatar_url":"https://github.com/rhx.png","language":"Swift","readme":"# SwiftGtk\n\nA Swift wrapper around gtk-3.x and gtk-4.x that is largely auto-generated from gobject-introspection.\nThis project tries to make gtk more \"swifty\" than using the plain C language interface.\nFor up to date (auto-generated) reference documentation, see https://rhx.github.io/SwiftGtk/\n\n![macOS 11 build](https://github.com/rhx/SwiftGtk/workflows/macOS%2011/badge.svg)\n![macOS 10.15 build](https://github.com/rhx/SwiftGtk/workflows/macOS%2010.15/badge.svg)\n![macOS gtk4 build](https://github.com/rhx/SwiftGtk/workflows/macOS%20gtk4/badge.svg)\n![Ubuntu 20.04 build](https://github.com/rhx/SwiftGtk/workflows/Ubuntu%2020.04/badge.svg)\n![Ubuntu 18.04 build](https://github.com/rhx/SwiftGtk/workflows/Ubuntu%2018.04/badge.svg)\n\n## What is new?\n\nSupport for gtk 4 was added via the `gtk4` branch.\n\nVersion 15 of gir2swift provides a Package Manager Plugin.  This requires Swift 5.6 or higher\n(older versions can be used via the [swift52](https://github.com/rhx/SwiftGtk/tree/swift52) branch).\n\n## Usage\n\nNormally, you don't build this package directly (but for testing you can - see 'Building' below). Instead you need to embed SwiftGtk into your own project using the [Swift Package Manager](https://swift.org/package-manager/).  After installing the prerequisites (see 'Prerequisites' below), you can do this by creating a new, empty project folder and then running the [projgen.sh](https://github.com/rhx/SwiftGtk/blob/gtk3/projgen.sh) script, e.g.:\n```\nmkdir MyProject\ncd MyProject\ncurl -L https://git.io/SwiftGtk3.sh | sh\n```\n\nAfter this, you should be able to `import Gtk` in your sources and use `swift build` to build your project.\nAlternatively, you can manually download [run-gir2swift.sh](https://github.com/rhx/gir2swift/raw/main/run-gir2swift.sh ) and add `SwiftGtk` as a dependency to your `Package.swift` file, e.g.:\n\n```Swift\n// swift-tools-version:5.6\n\nimport PackageDescription\n\nlet package = Package(name: \"MyPackage\",\n    dependencies: [\n        .package(url: \"https://github.com/rhx/gir2swift.git\", branch: \"main\"),\n        .package(url: \"https://github.com/rhx/SwiftGtk.git\",  branch: \"gtk3\"),\n    ],\n    targets: [\n        .target(name: \"MyPackage\",\n                dependencies: [\n                    .product(name: \"Gtk\", package: \"SwiftGtk\")\n                ]\n        )\n    ]\n)\n```\n\nFor gtk4 replace `.branch(\"gtk3\")` with `.branch(\"gtk4\")`.\n\n### Examples\n\nYou can find some example projects on GitHub that show how to use SwiftGtk:\n\n * [SwiftHelloGtk](https://github.com/rhx/SwiftHelloGtk)\n * [SwiftHelloGtkRadioButtons](https://github.com/rhx/SwiftHelloGtkRadioButtons)\n * [SwiftGtkListViewDemo](https://github.com/rhx/SwiftGtkListViewDemo)\n * [SwiftGtkListBoxDNDDemo](https://github.com/rhx/SwiftGtkListBoxDNDDemo)\n * [SwiftHelloGtkBuilder](https://github.com/rhx/SwiftHelloGtkBuilder)\n * [SwiftHelloCairoGtk](https://github.com/rhx/SwiftHelloCairoGtk)\n * [SwiftGtkCairoAnimationDemo](https://github.com/rhx/SwiftGtkCairoAnimationDemo)\n\n\n### Build Scripts\n\nThe demo applications come with build scripts that configure some environment variables and pass required arguments when calling `swift build`, `swift package`, etc.  The easiest way to get started is to clone one of the following projects, then copy all the `*.sh` shell scripts into your own project.  Also, if you want to be able to build a desktop app, create a `Resources` folder, and copy (at least) the `Info.plist` file as well:\n\n * [SwiftHelloGtk](https://github.com/rhx/SwiftHelloGtk): this is a quick starting point for a simple gtk app that does not need any resources.\n * [SwiftHelloGtkBuilder](https://github.com/rhx/SwiftHelloGtkBuilder): this is a good starting point for a more complex app that has user interface files (`*.ui`) for GtkBuilder in its `Resources` folder.\n \nYou can build, test, or run your project using the usual Swift compiler commands:\n```\nswift build\nswift test\nswift run\n```\n\nYou can also build the project using Xcode on macOS instead.  To do this, you need to create an Xcode project first, then open the project in the Xcode IDE:\n\n\t./xcodegen.sh\n\topen MyPackage.xcodeproj\n\nAfter that, use the (usual) Build and Test buttons to build/test this package.  Please note that, at this stage, the Swift Package manager is not able to create App targets for Xcode (so to build a macOs app rather than just a command line executable, you still need to use the `build.sh` script that calls `app-wrapper.sh` to create the standalone app bundle).\n\n\n## Prerequisites\n\n### Swift 5.6 or higher\n\nTo build, download Swift from https://swift.org/download/ -- if you are using macOS, make sure you have the command line tools installed as well).  Test that your compiler works using `swift --version`, which should give you something like\n\n\t$ swift --version\n\tswift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)\n    Target: arm64-apple-macosx13.0\n\non macOS, or on Linux you should get something like:\n\n\t$ swift --version\n\tSwift version 5.10 (swift-5.10-RELEASE)\n\tTarget: x86_64-unknown-linux-gnu\n\n### Gtk 3.22 or higher\n\nThe Swift wrappers have been tested with glib-2.56, 2.58, 2.60, 2.62, 2.64, 2.66, 2.68, 2.70, 2.72, 2.74, 2.76, 2.78 and 2.80, and gdk/gtk 3.22, 3.24 as well as 4.0, 4.2, 4.4, 4.6, 4.8, 4.10, 4.12, and 4.14 on the `gtk4` branch.  They should work with higher versions, but YMMV.  Also make sure you have `gobject-introspection` and its `.gir` files installed.\n\n#### Linux\n\n##### Ubuntu\n\nOn Ubuntu 22.04, 20.04, and 18.04, you can use the gtk that comes with the distribution.  Just install with the `apt` package manager:\n\n\tsudo apt update\n\tsudo apt install libgtk-3-dev gir1.2-gtksource-3.0 libcogl-pango-dev libcogl-path-dev libcogl-dev libpango1.0-dev gir1.2-pango-1.0 libgdk-pixbuf2.0-dev gir1.2-gdkpixbuf-2.0 libgraphene-1.0-dev gir1.2-graphene-1.0 libglib2.0-dev glib-networking gobject-introspection libgirepository1.0-dev libxml2-dev jq\n\nUbuntu 18.04 also requires you to install `libcogl-gles2-dev`.\n\n##### Fedora\n\nOn Fedora, you can use the gtk that comes with the distribution.  Just install with the `dnf` package manager:\n\n\tsudo dnf install gtk3-devel pango-devel cairo-devel cairo-gobject-devel glib2-devel gobject-introspection-devel libxml2-devel jq\n\n#### macOS\n\nOn macOS, you can install gtk using HomeBrew (for setup instructions, see http://brew.sh).  Once you have a running HomeBrew installation, you can use it to install a native version of gtk:\n\n\tbrew update\n\tbrew install gtk+3 glib glib-networking gobject-introspection pkg-config jq\n\n\n## Building\n\nAs pointed out in the 'Usage' section above, you don't normally build this package directly, but instead you embed it into your own project.  However, you can build and test this module separately to ensure that everything works.  Make sure you have all the prerequisites installed (see above).  After that, you can simply clone this repository and build the command line executable (be patient, this will download all the required dependencies and take a while to compile) using\n\n\tgit clone https://github.com/rhx/SwiftGtk.git\n\tcd SwiftGtk\n    swift build\n    swift test\n\n\n## Documentation\n\nYou can find reference documentation inside the [docs](https://rhx.github.io/SwiftGLib/) folder.\nThis was generated using the [jazzy](https://github.com/realm/jazzy) tool.\nIf you want to generate your own documentation, matching your local installation,\nyou can use the `generate-documentation.sh` script in the repository.\nMake sure you have [sourcekitten](https://github.com/jpsim/SourceKitten) and [jazzy](https://github.com/realm/jazzy) installed, e.g. on macOS:\n\n\tbrew install sourcekitten\n\tsudo gem install jazzy\n\t./generate-documentation.sh\n\n\n## Troubleshooting\n\nHere are some common errors you might encounter and how to fix them.\n\n### SwiftGtk takes a very long time to build\n\nYes, `gtk` is a huge beast.  The Swift interface generated from the `gtk` header files is close to 300,000 lines.  This takes some time to build!\n\n### Missing `.gir` Files\nIf you get an error such as\n\n\tGirs located at\n\tCannot open '/GLib-2.0.gir': No such file or directory\n\nMake sure that you have the relevant `gobject-introspection` packages installed (as per the Pre-requisites section), including their `.gir` and `.pc` files.\n\n### Old Swift toolchain or Xcode\n\nIf, when you run `swift build`, you get a `Segmentation fault (core dumped)` or circular dependency error such as\n\n\twarning: circular dependency detected while parsing pangocairo: harfbuzz -\u003e freetype2 -\u003e harfbuzz\n\t\nthis probably means that your Swift toolchain is too old, particularly on Linux (at the time of this writing, at least Swift 5.6 is required).  Make sure the latest toolchain is the one that is found when you run the Swift compiler (see above).\n\n  If you get an older version, make sure that the right version of the swift compiler is found first in your `PATH`.  On macOS, use xcode-select to select and install the latest version, e.g.:\n\n\tsudo xcode-select -s /Applications/Xcode.app\n\txcode-select --install\n","funding_links":[],"categories":["Swift","Libraries And Frameworks"],"sub_categories":["Swift"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhx%2FSwiftGtk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhx%2FSwiftGtk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhx%2FSwiftGtk/lists"}