2016-06-09 62 views
0

我正在用Eureka表單構建器構建表單,但不明白我如何獲取表單中的值。 They provide instructions in the docs hereSwift:如何使用Eureka表單構建器獲取表單值?

表單結果傳遞給詞典:

正如你可能已經注意到了,結果辭典鍵是行標籤值 和值是該行的值。只有具有標記值的行將被添加到字典中,並將 。

我的代碼:

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"]) 

} 

在這裏,公衆FUNC,使字典

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 
    } 
} 

回答

5

我想通了自己。我並不清楚您需要在要從中檢索的行上設置標籤:

<<< NameRow() { 
    $0.tag = "NameRow" 
    $0.title = "Name:" 
    $0.value = "My name" 
} 

let dict = form.values(includeHidden: true) 

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