Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[220826] TIL #115

Closed
Taehyeon-Kim opened this issue Aug 26, 2022 · 6 comments
Closed

[220826] TIL #115

Taehyeon-Kim opened this issue Aug 26, 2022 · 6 comments
Assignees

Comments

@Taehyeon-Kim
Copy link
Owner

Taehyeon-Kim commented Aug 26, 2022

  • 이제 뷰에 대해서 달라지는 것은 거의 없다. 레이아웃 짜는 것은 거의 동일하고, 고려해야 할 부분은 Dynamic하게 들어오는 데이터를 어떻게 처리하고 관리할 수 있을지를 고민하는 것이 더 좋을 것 같다.
  • Realm, TableView 갱신, TableView 로드
@Taehyeon-Kim
Copy link
Owner Author

Taehyeon-Kim commented Aug 26, 2022

삭제 시 문제 발생

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let favorite = UIContextualAction(style: .normal, title: "삭제") { action, view, completion in
        
        // - 프로퍼티로 관리
        // - 1. 데이터에 대한 정확성
        // - 2. 가독성
        let task = self.tasks[indexPath.row]
        
        // 삭제시 같은 데이터에 대해 동시에 접근하다보면 문제가 발생할 수 있음
        // - Record -> Image (문제 발생)
        // - Image -> Record (순서 변경 시 문제 해결) => 근본적인 해결책은 아님.
        
        self.removeImageFromDocument(fileName: "\(task).jpg")
        try! self.realm.write {
            self.realm.delete(task)
        }
        self.readDiary()
    }
    
    return UISwipeActionsConfiguration(actions: [favorite])
}

@Taehyeon-Kim
Copy link
Owner Author

Taehyeon-Kim commented Aug 26, 2022

tableView.beginUpdates()
tableView.endUpdates()

@Taehyeon-Kim
Copy link
Owner Author

  • Realm은 Table(데이터)을 자동으로 동기화하고 있다. 그렇기 때문에 View를 갱신하기만 하더라도 데이터를 뷰에 정상적으로 반영할 수 있다.
  • 정렬 또는 필터 등을 사용했을 때는 새롭게 만들어진 인덱스, 레코드로 가져올 필요가 있기 때문에 fetchRealm(custom function)으로 새롭게 데이터를 로드해 올 필요가 있다.

@Taehyeon-Kim
Copy link
Owner Author

Taehyeon-Kim commented Aug 26, 2022

데이터베이스 코드에 대한 정리

필요성이 느껴진다면 코드를 개선해보자.

문제 상황

  • 뷰 컨트롤러 여기저기에 코드가 너무 산재되어 있다.
  • 뷰 컨트롤러가 더 많아지는 순간 어떻게 해야할까
  • 새로운 컬럼이 추가된다거나 컬럼의 이름이 변경되어야 한다면, 테이블명이 변경되어야 한다면 모든 뷰 컨트롤러의 코드가 수정되어야 한다.

Repository Pattern

  1. Protocol로 필요한 메서드를 모두 만들어준다.
  2. 의존성 주입

@Taehyeon-Kim
Copy link
Owner Author

Taehyeon-Kim commented Aug 26, 2022

최적화

https://github.com/apple/swift/blob/main/docs/OptimizationTips.rst

Swift Optimization Level

Release(Production Mode)일 때는 최적화 필요

  1. Onone
  2. O
  3. OSize

스크린샷 2022-08-26 오후 12 17 52

WMO(Whole Module Optimization)

전체 모듈 최적화

스크린샷 2022-08-26 오후 12 51 04

  • WMO는 자동으로 적용되어 있음
  • WMO를 해제하면 private 키워드가 결국 의미 없어짐

@Taehyeon-Kim
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant