# SwiftFileBuilder for programmatic Swift code generation

**URL:** <https://forums.swift.org/t/swiftfilebuilder-for-programmatic-swift-code-generation/87290>\
**Category:** Community Showcase\
**Created:** [June 11, 2026, 4:36am UTC](https://forums.swift.org/t/swiftfilebuilder-for-programmatic-swift-code-generation/87290 "2026-06-11T04:36:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joehink](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joehink/32/45590_2.png) [@joehink](https://forums.swift.org/u/joehink)\
**Post date:** [June 11, 2026, 4:36am UTC](https://forums.swift.org/t/swiftfilebuilder-for-programmatic-swift-code-generation/87290/1 "2026-06-11T04:36:54Z")

</div>

I'm open sourcing my library SwiftFileBuilder.

> **[GitHub - joehinkle11/SwiftFileBuilder](https://github.com/joehinkle11/SwiftFileBuilder)**
>
> Contribute to joehinkle11/SwiftFileBuilder development by creating an account on GitHub.

Build your source file like this:

```swift
import SwiftFileBuilder

var file = SwiftFileBuilder()

file.appendImport(module: "Foundation")

file.appendType(accessLevel: .public, kind: .struct, name: "Person") { type in
    type.appendStoredProperty(accessLevel: .public, name: "name", type: "String")
    type.appendStoredProperty(accessLevel: .public, name: "age", type: "Int")

    type.appendInitializer(accessLevel: .public, arguments: [
        SwiftFunctionArgument(name: "name", type: "String"),
        SwiftFunctionArgument(name: "age", type: "Int"),
    ]) { fn in
        fn.append(line: "self.name = name")
        fn.append(line: "self.age = age")
    }
}

let output = file.finalize()

```

And you'll have an output file perfectly indented!

```swift
import Foundation

public struct Person {
    public var name: String
    public var age: Int

    public init(name: String, age: Int) {
        self.name = name
        self.age = age
    }
}

```

I developed this code generation tool for my [Swift interpreter project](https://forums.swift.org/t/demo-of-my-swift-interpreter-that-uses-swiftsyntax/44379/20). This also marks the last external dependency SwiftLite (the interpreter) needed to be open sourced. Now I can begin open sourcing the interpreter itself...which will take awhile.
