我对 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' produces '[T]', not the expected contextual result type '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?
作为值的字典。
您可以尝试将 invoiceParams
的声明更改为类似 var invoiceParams: [String: [Any]] = [:]
的内容。
因为我不知道 Eureka
这只是一个猜测。但我希望它仍然能有所帮助。
关于ios - Eureka SelectableSection 从 selectedRows 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40197797/