study

UICollectionViewCompostionalLayout

Diffable Data Source

<aside> 💡 apple documentation <Updating Collection Views Using Diffable Data Sources> 참고

</aside>

Define the Diffable Data Source

// 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]
}

Configure the Diffable Data Source

  1. Cell Registration