[英]Eureka SelectableSection get value from 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!})
map”產生“ [T]”,而不是預期的上下文結果類型“ AnyObject?”
這是什么問題? 這與swift 2.3上的早期版本一起使用。
據我從SelectableSection.swift中看到的, selectedRows
返回一個SelectableRow
項的數組:
public func selectedRows() -> [SelectableRow] {
return filter({ (row: BaseRow) -> Bool in
row is SelectableRow && row.baseValue != nil
}).map({ $0 as! SelectableRow})
}
因此map
函數也返回一個數組。
您的invoiceParams
似乎是需要AnyObject?
的字典AnyObject?
作為價值。
您可以嘗試將invoiceParams
的聲明更改為類似var invoiceParams: [String: [Any]] = [:]
。
由於我不知道Eureka
這只是一個猜測。 但我希望它仍然能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.