Swiftpack.co - robb/Swim as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by robb.
robb/Swim 0.4.0
A DSL for writing HTML in Swift
⭐️ 245
🕓 8 weeks ago
.package(url: "https://github.com/robb/Swim.git", from: "0.4.0")

Swim – Swift Markup

A DSL for building HTML documents with Swift function builders.

Currently in use on my personal website.

import Swim
import HTML

let myDocument = html(lang: "en-US") {
    head {
        meta(charset: "utf-8", content: "text/html", httpEquiv: "Content-Type")
    body(customAttributes: [ "data-foo": "bar" ]) {
        article(classes: "readme", "modern") {
            header {
                h1 {
                    "This is a great article."

            p {
                "Hello World!"
                "How are you?"

            p {
                "This is a"
                a(href: "https://swift.org") { "link to the Swift website" }

By generating all words in the language according to the HTML specification, we can make sure that only valid HTML can be expressed.

For example, the above would generate this HTML:

<html lang="en-US">
    <meta http-equiv="Content-Type" charset="utf-8" content="text/html" />
  <body data-foo="bar">
    <article class="readme modern">
          This is a great article.
        Hello World!
        How are you?
        This is a
        <a href="https://swift.org">
          link to the Swift website


Stars: 245
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.4.0: Explicit Void
8 weeks ago
  • Fixes support for Swift 5.6 thanks to @kevinrenskers in #40.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics