NEULiee / iOS-App-Dev-Tutorials

Apple 개발자 홈페이지의 UIKit 튜토리얼을 보고 정리하는 repository 입니다.
0 stars 0 forks source link

2. Collection Views and Navigation #6

Closed NEULiee closed 2 years ago

NEULiee commented 2 years ago

Adopting Collection Views

NEULiee commented 2 years ago

Adopting Collection Views

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

image

image

NEULiee commented 2 years ago

Displaying Cell Info

Use Foundation framework's date-formatting APIs to display accurate date and time information for every user's locale.

Learned

Blog - Format the Date and Time

Learned

NEULiee commented 2 years ago

Making Reminders Identifiable

diffable data source 는 collection view 의 item 들의 identifier 의 리스트를 저장합니다. reminder model 을 identifiable 하게 만들어서 각각의 reminder 를 unique 하고 identify 하게 만듭니다.

Learned

  1. Make the Model Identifiable

    • var id: String = UUID().uuidString 생성 (identifier) Blog post
  2. Create Functions for Accessing the model

    • extension Array where Element == Reminder
    • where 이란? Blog post
  3. Create a Custom Button Action

    • @objc func didPressDoneButton(_ sender: ReminderDoneButton) 함수 생성
  4. Wire a Target-Action Pair

    • Target-Action pattern
    • button.addTarget(self, action: #selector(didPressDoneButton(_:)), for: .touchUpInside)
  5. Update the Snapshot

    • diffable 데이터 소스로 작업할 때 데이터가 변경될 때 사용자 인터페이스를 업데이트하기 위해 스냅샷을 적용합니다.
    • 사용자가 완료 버튼을 탭할 때 새 스냅샷을 만들고 적용
  6. Make the Action Accessible

    • VoiceOver
  7. Preview Using the Accessibility Inspector

    • 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

NEULiee commented 2 years ago

Displaying Reminder Details

Reminder 상세 페이지를 구현합니다. CollectionView를 사용합니다.

image

Learned

  1. Create a Reminder View

    • init 함수에서 Collection view의 레이아웃 구현
    • required init?(coder: NSCoder) 이란?
      • ReminderListViewController 와 같은 collection view인데 다르게 구현한 이유는 무엇일까
  2. Create an Enumeration for Rows

    • Enum 으로 Collection view의 행을 선언한 이유는?

      • 각 행에 대한 스타일 지정 및 이미지 선택이 간단하고 깔끔해지기 때문에
      • 뷰 컨트롤러가 각 행에 대해 적절한 텍스트를 제공하는데 간편하기 때문에
      • if 문을 사용하는 것보다 깔끔하고 후에 더 많은 세부 정보를 쉽게 추가할 수 있다.
    • Hashable 로 Enum 을 선언한 이유는?

      • diffable datasource의 항목은 Hashable 을 준수해야하기 때문에 (conform hashable)
      • diffable datasource는 hash value를 사용하여 두 Snapshot의 데이터간에 변경된 사항을 확인한다.
  3. Set Up the Data Source

    • cell.defaultContentConfiguration()
    • default 말고 다른 cell configuration 찾아보기
  4. Set Up a Snapshot

    • updateSnapshot()
      var snapshot = Snapshot()
      snapshot.appendSections([0])
      snapshot.appendItems([.viewTitle, .viewDate, .viewTime, .viewNotes], toSection: 0)
      dataSource.apply(snapshot)
    • snapshot의 일부 Section에 appendItems 방법은?
  5. Display the Detail View

    • pushViewController
  6. Style the Navigation

    • AppDelegate.swift 의 application(_:didFinishLaunchingWithOptions:) 함수에서 앱의 모든 navigation bar 의 tint color 를 변경할 수 있습니다.
    • UINavigationBarAppearance() 의 인스턴스 메서드 configureWithOpaqueBackground()를 호출하여 네비게이션 바를 불투명한 배경으로 바꿀 수 있습니다.
    • UINavigationBar.appearance().scrollEdgeAppearance = navBarAppearance : 더 알아보기



Quiz

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을 사용하여 렌더링 한 것을 말하는 듯 합니다.