Tips for strong typed xml attribute composition (builder)
<p>I'm working on a xml builder that conforms to specific attribute restrictions in it's elements. For example, this Person element's only valid attribute would be "gender" and the value can only be "male" or "female."</p>

<p>Right now, I'm using a <code>[String:String]</code> for attribute key/values. I'd like a strongly typed way to force these restrictions per each unique element attribute requirement. </p>

<p>I'm at a loss for a Swift way of doing this. Any ideas would be greatly appreciated. Thanks!</p>

<pre><code>extension XmlBuilder {
    func person(text: String? = "", attributes: [String:String] = [String:String]()) -&gt; XmlBuilder {
        fn = compose(fn, { doc in
            doc.root.addChild(name: "Person", value: text, attributes: attributes)
            return doc
        })
        return self
    }
}

let xml = XmlBuilder()
    .person("Jon", attributes: ["gender":"male"])
    .construct()
</code></pre>