RLMCollectionChange

Objective-C

@interface RLMCollectionChange : NSObject

迅速

@_nonSendable(_assumed) class RLMCollectionChange : NSObject

RLMCollectionChange对象封装有关 Realm 通知所报告的collection变更的信息。

RLMCollectionChange 传递到在RLMArrayRLMResults上向-addNotificationBlock注册的通知块,并报告自上次调用通知块以来collection中的哪些行发生了更改。

更改信息有两种格式:集合中每种更改类型的行索引的简单数组,以及请求部分中适合直接传递给UITableView的批量更新方法的索引路径数组。 更新名为tvUITableView的完整示例:

[tv beginUpdates];
[tv deleteRowsAtIndexPaths:[changes deletionsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[tv insertRowsAtIndexPaths:[changes insertionsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[tv reloadRowsAtIndexPaths:[changes modificationsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[tv endUpdates];

RLMCollectionChange中的所有数组始终按升序排序。

  • 先前版本的集合中已从本版本中删除的对象的索引。

    声明

    Objective-C

    @property (nonatomic, readonly) NSArray<NSNumber *> *_Nonnull deletions;

    迅速

    var deletions: [NSNumber] { get }
  • 新插入的新版本集合中的索引。

    声明

    Objective-C

    @property (nonatomic, readonly) NSArray<NSNumber *> *_Nonnull insertions;

    迅速

    var insertions: [NSNumber] { get }
  • 新版本collection中已修改的索引。

    对于RLMResults ,这意味着位于该索引处的对象的一个或多个属性已被修改(或者该对象链接到的对象已被修改)。

    对于RLMArray ,数组本身被修改为包含该索引处的不同对象也将被报告为修改。

    声明

    Objective-C

    @property (nonatomic, readonly) NSArray<NSNumber *> *_Nonnull modifications;

    迅速

    var modifications: [NSNumber] { get }
  • 返回给定节中删除索引的索引路径。

    声明

    Objective-C

    - (nonnull NSArray<NSIndexPath *> *)deletionsInSection:(NSUInteger)section;

    迅速

    func deletions(inSection section: UInt) -> [IndexPath]
  • 返回给定节中插入索引的索引路径。

    声明

    Objective-C

    - (nonnull NSArray<NSIndexPath *> *)insertionsInSection:(NSUInteger)section;

    迅速

    func insertions(inSection section: UInt) -> [IndexPath]
  • 返回给定部分中修改索引的索引路径。

    声明

    Objective-C

    - (nonnull NSArray<NSIndexPath *> *)modificationsInSection:(NSUInteger)section;

    迅速

    func modifications(inSection section: UInt) -> [IndexPath]