UIKit
프레임 워크에서 사용되는 UICollectionView
Class
에 대해 공식 문서를 번역해보고 공부해 봅니다.
An object that manages an ordered collection of data items and presents them using customizable layouts.
UICollectionView
객체는 정렬된 데이터의 컬렉션 items
를 관리하고 그것들을 customizable layouts
를 사용해서 보여줍니다.
@MainActor class UICollectionView: UIScrollView
선언부에는 @MainActor
노테이션과, UIScrollView
를 상속한다는 것을 확인 할 수 있습니다.
@MainActor
노테이션 같은 경우에는, Class
의 Behavior
가 Main Thread
에서 동작하게 하는 노테이션입니다. (문서참조)
또한, UIScrollView
를 상속한다는 것에 대해서, 어느정도 UIScrollView의 속성들을 가지고 있다고 유추 해 볼수 있겠습니다!
When you add a collection view to your user interface, your app’s main job is to manage the data associated with that collection view. The collection view gets its data from the data source object, stored in the collection view’s dataSource property. For your data source, you can use a UICollectionViewDiffableDataSource object, which provides the behavior you need to simply and efficiently manage updates to your collection view’s data and user interface. Alternatively, you can create a custom data source object by adopting the UICollectionViewDataSource protocol.
Data in the collection view is organized into individual items, which you can group into sections for presentation. An item is the smallest unit of data you want to present. For example, in a photos app, an item might be a single image. The collection view presents items onscreen using a cell, which is an instance of the UICollectionViewCell class that your data source configures and provides.
In addition to its cells, a collection view can present data using other types of views. These supplementary views can be, for example, section headers and footers that are separate from the individual cells but still convey information. Support for supplementary views is optional and defined by the collection view’s layout object, which is also responsible for defining the placement of those views.
Besides embedding a UICollectionView in your user interface, you use the methods of the collection view to ensure that the visual presentation of items matches the order in your data source object. A UICollectionViewDiffableDataSource object manages this process automatically. If you’re using a custom data source, then whenever you add, delete, or rearrange data in your collection, you use the methods of UICollectionView to insert, delete, and rearrange the corresponding cells.
You also use the collection view object to manage the selected items, although for this behavior the collection view works with its associated delegate object.
너무기네요;; 짧게 짧게 요약을 좀 해봅시다..!
Collection View
는 data
를 data source object
에서 가져옵니다.Collection View
는 data
를 Collection View
의 data Source
Property
에 저장합니다.data source
를 위해, UICollectionViewDiffableDataSource
객체를 사용할수 있습니다.UICollectionViewDiffableDataSource
는 간단하고 효율적인 updates
관리를 UI
에 제공합니다.UIColletionView
에서 시각적인 순서와 Data Source
객체의 순서를 자동적으로 관리해줍니다. (Identifiable
)UICollectionViewDataSource
프로토콜
을 채택함으로서 커스텀 data source object
를 만들수 있습니다.Collection View
의 데이터는 개별적인 Item
으로 구성이 됩니다.Item
은 표시하고자 하는 데이터의 최소 단위 입니다.Item
들을 Section
으로 그루핑해서 보여지게 만듭니다!Collection View
는 Cell
외에도, 다른 유형의 views
를 사용해서 데이터를 표시하는게 가능합니다. (ex, footer
, header
)Overview
에 크게 제시되어있는 내용말고도 Layout
, Cell and Supplementary views
, Data prefetching
, Reorder items interactivitvely
등 여러가지 내용이 더 있습니다.supplementary views
가 무엇인지 잘몰라서 서칭을 좀 해봤습니다.
일각에서는 colletion view
의 Header
+ Footer
를 합쳐서 spplementary views
라고 부른다고 하네요!