Im using the UICollectionViewCompositionalLayout to lay my collection view items side by side for landscape and single tile on normal mood. Thus, I use NSCollectionLayoutGroups to achieve this objective. I get the mentioned error when I define my group. My code as bellow.
private func layout() -> UICollectionViewCompositionalLayout {
let layout = UICollectionViewCompositionalLayout { sectionIndex, environment -> NSCollectionLayoutSection? in
let itemSize = NSCollectionLayoutSize (
widthDimension: .fractionalWidth(0.2),
heightDimension: .estimated(400)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize (
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(400)
)
let columns = (environment.container.contentSize.width > 500 && self.toggleSwitch.isOn) ? 2 : 1
//MARK: Error horizontal(layoutSize:subitem:count:)' was deprecated in iOS 16.0
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: columns)
group.interItemSpacing = .fixed(20)
if columns > 1 {
group.contentInsets.leading = 20
group.contentInsets.trailing = 20
}
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 20
section.contentInsets.top = 20
return section
}
let config = UICollectionViewCompositionalLayoutConfiguration()
config.interSectionSpacing = 50
layout.configuration = config
return layout
}
It's been replaced with horizontal(layoutSize:repeatingSubitem:count:)
instead as documented on Apple's developer site. This is how you would update your code:
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, repeatingSubitem: item, count: columns)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With