无法转换类型' [CustomObject]'的值预期的论证类型' [_]'

时间:2017-02-02 10:17:35

标签: ios swift xcode generics swift3

这是类声明:

class VXDropdownFormRow<T: SelectableOption>: DropdownFormRow<T> where T: Equatable {
    override init(title: String?, options: [T], selectedOption: T?, cellSelection: FormCellSelectionClosureType?, valueChanged: ((FormRow) -> Void)?) {
        super.init(title: title, options: options, selectedOption: selectedOption, cellSelection: cellSelection, valueChanged: valueChanged)
        self.cellHeight = 74
    }
}

我是从另一个班级打来的:

formRow = VXDropdownFormRow(标题:NSLocalizedString(&#34; xyz&#34;,评论:&#34;&#34;)。uppercased(),options:durationArray,selectedOption:contractDurationtItem,cellSelection:nil,valueChanged: {(行)in                 self.contract.duration = row.value as?合同期限             })

durationArray是:

var durationArray : [ListItem]

符合协议SelectableOption,就像在类的声明中所说的那样:

open class ListItem: NSManagedObject, SelectableOption {
    func setValues(fromJSON json: JSON, sortOrder: Int) {
        defaultValue = json["default"].stringValue == "true" ?  (true) : (false)
        value = json["value"].stringValue
        text = json["text"].stringValue
        localSortOrder = (sortOrder as NSNumber?)
    }
    public func selectableOptionTitle() -> String {
        return self.text!
    }
    public func selectableOptionSectionTitle() -> String {
        return ""
    }

} 

但编译器在构建时会抛出错误:

Cannot convert value of type '[ListItem]' to expected argument type '[_]'

Error

我该怎么做才能解决这个错误?

1 个答案:

答案 0 :(得分:0)

我通过修复设置为VXDropdownFormRow<OldClassName>的文件中的原始声明来解决问题。请检查声明以确保一切正常。此错误具有误导性,并不能帮助您找到问题。