0Pricing
Swift Academy · Lesson

Practical examples without UI frameworks

Write small, useful DSLs without UI: config files, simple query builders, text/Markdown emitters, and validation pipelines with @resultBuilder .

Non-UI result builders

You can build handy DSLs for many tasks beyond UI. We will craft config, query, text, and validation builders. Keep each one tiny and focused.

Config builder

A config builder collects simple tuples into a dictionary. Call sites are neat and easy to scan.

@resultBuilder
struct ConfigBuilder {
    static func buildBlock(_ parts: (String,String)...) -> [String:String] {
        var dict: [String:String] = [:]
        for (k,v) in parts { dict[k] = v }
        return dict
    }
}
func config(@ConfigBuilder _ body: () -> [String:String]) -> [String:String] { body() }

// Use it:
let cfg = config {
    ("ENV", "debug")
    ("API_URL", "https://api.example.com")
    ("RETRY", "3")
}
print(cfg["API_URL"] ?? "missing")

All lessons in this course

  1. Building mini-DSLs with result builders
  2. Scoped APIs & readability patterns
  3. Practical examples without UI frameworks
← Back to Swift Academy