Swift言語の機能で作るHTMLBuilder by 日向強

iOSDC Japan 2021
レギュラートーク(20分)

Swift言語の機能で作るHTMLBuilder

coffeegyunyu 日向強 coffeegyunyu
2

Swiftはバージョンアップのたびに、様々な機能が追加されるのも魅力です。
そんなSwiftの機能を、HTMLをお手軽に作成するHTMLビルダーを例にしてご紹介するセッションになります。

Swiftの言語機能を活かして、ちょっと実装をするだけでHTMLが出力できるようになります。

html.children {
    head.children {
        meta(charset: "UTF-8")
        meta(name: "description", content: "Free Web tutorials")
        meta(name: "keywords", content: "HTML, CSS, JavaScript")
        meta(name: "author", content: "John Doe")
    }
    body.children {
        p.children {
            "All meta information goes inside the head section."
        }
    }
}

このセッションでは、以下の機能を使って、HTMLBuilderを作り、そのそれぞれの機能をご紹介できればと思います。

  • @dynamicMemberLookup
  • @dynamicCallable
  • @resultBuilder