Closed NEULiee closed 2 years ago
Collection views manage ordered collections of data items and use customizable layouts to present them. Adopting Collection views help you separate concerns of data, layout and presentation, resulting in an app that's more robust and extensible
Use Foundation framework's date-formatting APIs to display accurate date and time information for every user's locale.
Blog - Format the Date and Time
diffable data source 는 collection view 의 item 들의 identifier 의 리스트를 저장합니다. reminder model 을 identifiable 하게 만들어서 각각의 reminder 를 unique 하고 identify 하게 만듭니다.
Make the Model Identifiable
var id: String = UUID().uuidString
생성 (identifier) Blog postCreate Functions for Accessing the model
extension Array where Element == Reminder
Create a Custom Button Action
@objc func didPressDoneButton(_ sender: ReminderDoneButton)
함수 생성Wire a Target-Action Pair
button.addTarget(self, action: #selector(didPressDoneButton(_:)), for: .touchUpInside)
Update the Snapshot
Make the Action Accessible
Preview Using the Accessibility Inspector
Quiz1. Which structure conforms to the Identifiable protocol?
struct Article {
var id: String
var title: String
var excerpt: String
var content: String
}
// Identifiable 프로토콜을 선언하지 않음
struct Article: Identifiable {
var id: UUID
var title: String
var excerpt: String
var content: String
}
// correct: This structure declares conformance to Identifiable and has the required id property.
struct Article: Identifiable {
var identifier: String = UUID().uuidString
var title: String
var excerpt: String
var content: String
}
// identifier is not Identifiable property
Quiz2. Which object receives a message when a user taps the button?
class CustomViewController: UIViewController {
var button: UIButton!
var dataSource: UICollectionViewDataSource!
override func viewDidLoad() {
super.viewDidLoad()
button = UIButton()
button.addTarget(self, action: #selector(processButtonPress), for: .touchUpInside)
}
@objc func processButtonPress() {... }
}
A. The view controller
Reminder 상세 페이지를 구현합니다. CollectionView를 사용합니다.
Create a Reminder View
required init?(coder: NSCoder)
이란?
Create an Enumeration for Rows
Enum 으로 Collection view의 행을 선언한 이유는?
Hashable 로 Enum 을 선언한 이유는?
Set Up the Data Source
Set Up a Snapshot
var snapshot = Snapshot()
snapshot.appendSections([0])
snapshot.appendItems([.viewTitle, .viewDate, .viewTime, .viewNotes], toSection: 0)
dataSource.apply(snapshot)
Display the Detail View
Style the Navigation
application(_:didFinishLaunchingWithOptions:)
함수에서
앱의 모든 navigation bar 의 tint color 를 변경할 수 있습니다.UINavigationBarAppearance()
의 인스턴스 메서드 configureWithOpaqueBackground()
를
호출하여 네비게이션 바를 불투명한 배경으로 바꿀 수 있습니다.UINavigationBar.appearance().scrollEdgeAppearance = navBarAppearance
: 더 알아보기Q. What can improve table view performance when processing large quantities of data?
A. Reusing cells
Dequeueing reusable cells ensures that table views can perform well even processing large quantities of data.
Q. UIKit diffable data sources display generic items in a list. How do you notify your diffable data source about the specific type of information that you want to display in the list?
A. Create your diffable data source with your information type as a generic parameter input to the generic class.
When you create a diffable data source, you can use generic parameters to give the system the specific types to use when displaying information in the collection view.
Q. What's the easiest strategy for customizing the image variant that the system renders in your app?
A. Create and customize an image configuration object.
System images contain multiple variants to account for such factors as whether the interface is light or dark. You can override the image configuration object and customize its attributes. Then, the system renders the image that’s appropriate for the environment and your specifications.
-> 아마 여기서 enum을 사용하여 렌더링 한 것을 말하는 듯 합니다.
Adopting Collection Views