RealmCollectionChange

@frozen
public enum RealmCollectionChange<CollectionType>

RealmCollectionChange 값은 Realm 알림에서 보고하는 컬렉션의 변경 사항에 대한 정보를 캡슐화합니다.

변경 정보는 각 변경 유형에 대한 collection의 간단한 행 인덱스 배열과 UITableView의 배치 업데이트 메서드에 직접 전달하기에 적합한 요청된 섹션의 인덱스 경로 배열, 두 가지 형식으로 제공됩니다.

.update 경우의 인덱스 배열은 UITableView의 배치 규칙을 따르며, 인덱스 경로로 변환된 후 테이블 뷰의 배치 업데이트 함수에 그대로 전달될 수 있습니다. 예를 들어 간단한 1 섹션 테이블 보기의 경우 다음을 수행할 수 있습니다.

self.notificationToken = results.observe { changes in
    switch changes {
    case .initial:
        // Results are now populated and can be accessed without blocking the UI
        self.tableView.reloadData()
        break
    case .update(_, let deletions, let insertions, let modifications):
        // Query results have changed, so apply them to the TableView
        self.tableView.beginUpdates()
        self.tableView.insertRows(at: insertions.map { IndexPath(row: $0, section: 0) },
           with: .automatic)
        self.tableView.deleteRows(at: deletions.map { IndexPath(row: $0, section: 0) },
           with: .automatic)
        self.tableView.reloadRows(at: modifications.map { IndexPath(row: $0, section: 0) },
           with: .automatic)
        self.tableView.endUpdates()
        break
    case .error(let err):
        // An error occurred while opening the Realm file on the background worker thread
        fatalError("\(err)")
        break
    }
}
  • .initial 은(는) 쿼리의 초기 실행이 완료되었으며(해당되는 경우) 이제 차단 작업을 수행하지 않고도 컬렉션을 사용할 수 있음을 나타냅니다.

    선언

    스위프트

    case initial(CollectionType)
  • .update 는 쓰기 트랜잭션(write transaction)이 커밋되어 컬렉션에 있는 객체를 변경하거나 컬렉션에 있는 객체 중 하나 이상을 수정했음을 나타냅니다.

    세 가지 변경 배열 모두 항상 오름차순으로 정렬됩니다.

    선언

    스위프트

    case update(CollectionType, deletions: [Int], insertions: [Int], modifications: [Int])

    매개변수

    deletions

    이 컬렉션에서 제거된 이전 버전의 컬렉션에 있는 인덱스입니다.

    insertions

    이 버전에 추가된 새 collection의 인덱스입니다.

    modifications

    이 컬렉션의 이전 버전에서 수정된 객체의 인덱스입니다.

  • 더 이상 오류가 발생할 수 없습니다. 이 케이스는 사용되지 않으며 다음 주요 버전에서 제거될 예정입니다.

    선언

    스위프트

    case error(Error)