Swift: 如何使用 Eureka 表单生成器获取表单值?

Swift: How to get form values using Eureka form builder?

我正在使用 Eureka 表单生成器构建表单,但不明白如何获取表单中的值。 They provide instructions in the docs here.

表单结果被传递到字典:

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.

我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    form =

        Section()

        <<< NameRow() { // NameRow is dictionary key, right?
            [=11=].title = "Name:"
            [=11=].value = "My name" // This is what should be printed
        }

        let dict = form.values(includeHidden: true)

        // PROBLEM: This prints nil
        print(dict["NameRow"])

}

这里是 public 生成字典的函数

public func values(includeHidden includeHidden: Bool = false) -> [String: Any?]{
    if includeHidden {
        return allRows.filter({ [=12=].tag != nil })
            .reduce([String: Any?]()) {
                var result = [=12=]
                result[.tag!] = .baseValue
                return result
        }
    }
    return rows.filter({ [=12=].tag != nil })
        .reduce([String: Any?]()) {
            var result = [=12=]
            result[.tag!] = .baseValue
            return result
    }
}

我自己想出来了。我不是很清楚您需要在要从中检索值的行上设置标签:

<<< NameRow() {
    [=10=].tag = "NameRow"
    [=10=].title = "Name:"
    [=10=].value = "My name"
}

let dict = form.values(includeHidden: true)

print(dict["NameRow"]) // Prints my name