2016-10-22 86 views
0

我在SelectableSection中遇到了問題selectedRows()尤里卡SelectableSection從selectedRows中獲取值

使用Xcode 8,Swift 3,Eureka 2.0.0-beta.1。

func viewDidLoad() { 
    let branch_section = SelectableSection<ImageCheckRow<String>>("Branches", selectionType: .multipleSelection) 
    branch_section.tag = "branch_section" 
    for branch in branchList { 
     let branchStr = String(branch.id) 
     branch_section <<< ImageCheckRow<String>(branch.name){ row in 
      row.title = branch.name 
      row.selectableValue = branchStr 
      row.value = nil 
     } 
    } 
} 


@IBAction func saveFilter(_ sender: AnyObject) { 
    let branch_section = self.form.sectionBy(tag: "branch_section") as? SelectableSection<ImageCheckRow<String>>   
    invoiceParams["branches"] = branch_section!.selectedRows().map({$0.value!}) 
} 

現在我有問題,此線invoiceParams["branches"] = branch_section!.selectedRows().map({$0.value!})

地圖」產生 '[T]',而不是預期的上下文結果類型 'AnyObject?

這是什麼問題?這與swift 2.3以前的版本一起工作。

回答

1

據我可以從SelectableSection.swiftselectedRows回報SelectableRow項的數組看到:

public func selectedRows() -> [SelectableRow] { 
    return filter({ (row: BaseRow) -> Bool in 
     row is SelectableRow && row.baseValue != nil 
    }).map({ $0 as! SelectableRow}) 
} 

所以map功能也返回數組。

您的invoiceParams似乎是一個字典,它期望AnyObject?作爲值。

您可以嘗試將invoiceParams的聲明更改爲var invoiceParams: [String: [Any]] = [:]之類的內容。由於我不知道Eureka這只是一個猜測。但我希望它仍然有所幫助。

+0

實際上,聲明需要:'var invoiceParams:[String:Any] = [:]'但你的回答是正確的..謝謝.. –