project/개발 업무
UICollectionView Crashes on iOS 18 with Xcode 16: Troubleshooting Guide
lgvv
2024. 11. 22. 00:13
UICollectionView Crashes on iOS 18 with Xcode 16: Troubleshooting Guide
기존 운영중인 코드에서 Xcode 16, iOS 18 에서만 UICollectionView 크래시 발생
크래시 상황 분석
상황 분석
- Xcode 16 + iOS 17.7 ✅ 크래시 미발생
- Xcode 16 + iOS 18 + ❌ 크래시 발생
즉, Xcode 16과 iOS 18 기기 한정해서 발생하는 걸로 보임.
크래시 현상 재현 코드
deque를 2회이상 수행하면 크래시가 발생.
import UIKit
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
configureUI()
}
private lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.delegate = self
cv.dataSource = self
cv.register(CellA.self, forCellWithReuseIdentifier: CellA.id)
cv.register(CellB.self, forCellWithReuseIdentifier: CellB.id)
return cv
}()
private func configureUI() {
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// ❌ Crash
let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: CellA.id, for: indexPath)
let cellB = collectionView.dequeueReusableCell(withReuseIdentifier: CellB.id, for: indexPath)
return UICollectionViewCell()
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return .init(width: 100, height: 100)
}
}
class CellA: UICollectionViewCell {
static let id: String = String(describing: CellA.self)
}
class CellB: UICollectionViewCell {
static let id: String = String(describing: CellB.self)
}
스크린샷