比方說,我有覆蓋此功能,並在它的身上我沒有默認值定義的屬性爲什麼我們不必在函數體內提供屬性默認值?
let identifier: String
爲什麼迅速讓我跳過此屬性提供默認值?
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
}
另請參閱https://stackoverflow.com/a/28444671/1187415。 –