【发布时间】:2020-08-03 21:04:57
【问题描述】:
我想将T 类型传递给函数(例如,它包含RatingCell),但我不明白如何使T 类型完全定义为RatingCell
func configureQuestionCell<T>(cellType: T, question: Question, answers: [String]?) -> UITableViewCell {
let cell = self.blockContent.dequeueReusableCell(withIdentifier: ReusableCellID.pickerCell.rawValue) as! T
//Value of type 'T' has no member ...
cell.delegate = self
cell.questionId = question.questionId
cell.cellTitle.text = question.title
cell.answerVariants = question.answerVariants
if answers != nil {
cell.userAnswers = answers!
}
return cell
}
我在评论中添加错误。我也确定RatingCell 包含所有这些参数
【问题讨论】:
-
Swift programming language book,我认为阅读泛型和协议章节会对您有所帮助
标签: swift function class types