【发布时间】:2018-03-25 14:24:06
【问题描述】:
假设我已经覆盖了这个函数,并且在它的主体中我定义了没有默认值的属性
let identifier: String
为什么 swift 允许我跳过为这个属性提供默认值?
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let identifier: String
if indexPath.item == 1 {
identifier = trendingCellId
} else if indexPath.item == 2 {
identifier = subscriptionCellId
} else {
identifier = cellId
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath)
return cell
}
【问题讨论】:
标签: swift