问题
I'm building a form with the Eureka form builder but don't understand how I can get the values inside the form. They provide instructions in the docs here.
The form results are passed to a dictionary:
As you may have noticed the result dictionary key is the row tag value and the value is the row value. Only rows with a tag value will be added to the dictionary.
My code:
override func viewDidLoad() {
    super.viewDidLoad()
    form =
        Section()
        <<< NameRow() { // NameRow is dictionary key, right?
            $0.title = "Name:"
            $0.value = "My name" // This is what should be printed
        }
        let dict = form.values(includeHidden: true)
        // PROBLEM: This prints nil
        print(dict["NameRow"])
}
And here the public func that makes the dict
public func values(includeHidden includeHidden: Bool = false) -> [String: Any?]{
    if includeHidden {
        return allRows.filter({ $0.tag != nil })
            .reduce([String: Any?]()) {
                var result = $0
                result[$1.tag!] = $1.baseValue
                return result
        }
    }
    return rows.filter({ $0.tag != nil })
        .reduce([String: Any?]()) {
            var result = $0
            result[$1.tag!] = $1.baseValue
            return result
    }
}
    回答1:
I figured it out myself. It wasn't immediately clear to me that you need to set tags on the rows you want to retrieve the value from:
<<< NameRow() {
    $0.tag = "NameRow"
    $0.title = "Name:"
    $0.value = "My name"
}
let dict = form.values(includeHidden: true)
print(dict["NameRow"]) // Prints my name
    来源:https://stackoverflow.com/questions/37716588/swift-how-to-get-form-values-using-eureka-form-builder