1. 문자열
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell", for: indexPath) as! TestTableViewCell
return cell
}
2. Type Property
class TestTableViewCell: UITableViewCell {
static let identifier = "TestTableViewCell"
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: TestTableViewCell.identifier, for: indexPath) as! TestTableViewCell
return cell
}
3. Protocol + Extension
protocol ReuseIdentifierProtocol {
static var identifier: String { get }
}
extension UITableViewCell: ReuseIdentifierProtocol {
static var identifier: String {
return String(describing: self)
}
}
셀을 새로 만들 때마다 identifier를 만들 필요가 없어진다!
'iOS' 카테고리의 다른 글
| [iOS] Result Type으로 네트워크 통신 개선해보기 (0) | 2024.08.05 |
|---|---|
| [iOS] 싱글톤 패턴 (0) | 2024.07.30 |
| [iOS] Dispatch Queue (0) | 2024.07.18 |
| [iOS] 역값 전달 - 이전 화면에 값 전달하기 (0) | 2024.07.01 |
| [iOS] UIButton - Style: Default vs Plain (0) | 2024.06.25 |