AsyncRelationChangeObserver
public protocol AsyncRelationChangeObserver
There are two fundamental ways to asynchronously observe relations: change observation and content observation.
Change observation provides the deltas for each change. This is useful for things that need to know exactly what changed, perhaps so they can efficiently update some other thing derived from the Relation content.
Content observation provides the entire Relation content after each change. This is useful for things that don’t care about the details of which bits changed, just what the data looks like after the change.
Change observation is done by implementing AsyncRelationChangeObserver. The observer receives a willChange call any time an asynchronous update is scheduled for a Relation that the target Relation depends on. This happens regardless of whether the scheduled change actually alters the content of the target Relation, because figuring that out is expensive. The addedRows and removedRows methods are called zero or more times each to indicate new or deleted rows. If additional updates are made while this is in progress, the observer may receive redundant additions and removals (e.g. a row is shown as added, then as removed) during the same sequence of calls. When an update cycle is completed, didChange is called, if willChange was previously called.
Content observation is done by implementing AsyncRelationContentObserver. Like change observers, the observer receives a willChange call for any scheduled change to a dependent Relation. The newContents method is called zero or more times to report the new contents of the target Relation, and finally didChange is called.
Each type of observer also has a Coalesced variant. In this version, there’s only willChange and didChange, where didChange also reports the entire set of deltas (for change observers) or the entire new content of the target Relation (for content observers). This saves observers from buffering everything manually, for observers which need to have everything before they can take any action.
AsyncRelationChangeObserver Protocol Reference