UICollectionViewCompostionalLayout
<aside> 💡 apple documentation <Updating Collection Views Using Diffable Data Sources> 참고
</aside>
UICollectionViewDataSource
UICollectionViewDiffableDataSource
// ViewController
private var recipeListDataSource: UICollectionViewDiffableDataSource<RecipeListSection, Recipe.ID>!
// Section Identifier Type
private enum RecipeListSection: Int {
case main
}
// Item Identifier Type
struct Recipe: Identifiable, Codable {
var id: Int
var title: String
var prepTime: Int // In seconds.
var cookTime: Int // In seconds.
var servings: String
var ingredients: String
var directions: String
var isFavorite: Bool
var collections: [String]
fileprivate var addedOn: Date? = Date()
fileprivate var imageNames: [String]
}
Recipe.ID 타입으로 item identifier type을 정의한 경우, 전체 recipe가 아닌, id값만 저장된다. 일부 data만을 data source에 저장하는 전략은 collection view 퍼포먼스를 향상시킨다.UICollectionView.CellRegistration<Cell, Item>register() 을 호출하지 않아도 된다.)dequeueConfiguredReusableCell 의 인자로 이용한다.