RLMectionedResult

Objective-C

@protocol RLMSectionedResult <NSFastEnumeration, RLMThreadConfined>

迅速

protocol RLMSectionedResult : NSFastEnumeration, RLMThreadConfined

RLMSectionedResult协议定义了RLMSectionedResults and RLMSection

对象访问

  • 集合中对象的计数。

    声明

    Objective-C

    @property (nonatomic, readonly) NSUInteger count;

    迅速

    var count: UInt { get }
  • 返回collection中给定索引的对象。

    声明

    Objective-C

    - (nonnull id)objectAtIndexedSubscript:(NSUInteger)index;

    迅速

    subscript(index: UInt) -> Any { get }
  • 返回collection中给定索引的对象。

    声明

    Objective-C

    - (nonnull id)objectAtIndex:(NSUInteger)index;

    迅速

    func object(at index: UInt) -> Any

冻结

  • 返回此collection的冻结(不可变)快照。

    冻结副本是一个不可变的集合,其中包含与该集合当前包含的数据相同的数据,但在写入包含的 Realm 时不会更新。 与活动数组不同,冻结集合可以从任何线程访问。

    警告

    在写事务(write transaction)期间或当包含的 Realm 为只读时,无法调用此方法。

    警告

    在 Realm 上执行写事务(write transaction)时长时间持有冻结的 collection 可能会导致 Realm 文件过大。有关更多信息,请参阅RLMRealmConfiguration.maximumNumberOfActiveVersions

    声明

    Objective-C

    - (nonnull instancetype)freeze;

    迅速

    func freeze() -> Self
  • 返回此冻结collection的实时版本。

    此方法解析对同一冻结collection的实时副本的引用。如果在实时collection上调用,则返回自身。

    声明

    Objective-C

    - (nonnull instancetype)thaw;

    迅速

    func thaw() -> Self
  • 指示基础collection是否已冻结。

    冻结集合是不可变的,可以从任何线程访问。

    声明

    Objective-C

    @property (nonatomic, readonly, getter=isFrozen) BOOL frozen;

    迅速

    var isFrozen: Bool { get }

分段结果通知

  • 注册一个区块,以便在每次collection更改时调用。

    该区块将与初始分段结果集合一起异步调用,然后在每次写入事务后再次调用,这会更改结果中的任何对象或结果中的对象。

    首次调用该区块时, change参数将为nil 。 对于此后的每次调用,它将包含有关在该部分中添加、删除或修改了哪些行的信息。 如果写事务未修改该部分中的任何对象,则根本不会调用该区块。 有关如何报告更改的信息以及更新UITableView的示例,请参阅RLMSectionedResultsChange文档。

    调用该区块时, RLMSection / RLMSectionedResults对象将被全面评估并保持最新状态。

    通知是通过标准事件循环传递的,因此当事件循环被其他活动阻止时无法传递。当无法立即传递通知时,可以将多个通知合并为一个通知。 这可以包括带有初始结果的通知。 例如,以下代码在添加通知块后立即执行写事务(write transaction),因此没有机会首先传递初始通知。因此,初始通知将反映写事务(write transaction)后 Realm 的状态。

    RLMResults *results = [Dog allObjects]; RLMectionedResults *sectionedResults = [results sectionedResultsUsingKeyPath:@“age” ascending:YES]; self.token = [sectionedResults addNotificationBlock:^(RLMSectionedResults *sectionedResults, RLMSectionedResultsChange *changes) { // 仅对示例触发一次 NSLog(@“sectionedResults.count: %zu”, sectionedResults.count); // => 1 }]; [realm transactionWithBlock:^{ Dog *dog = [[Dog alloc] init]; dog.name = @“Rex”; dog.age = 5 ; [realm addObject:dog]; }]; // 运行循环执行上下文结束

    只要您希望继续将更新发送到区块,就必须保留返回的令牌。 要停止接收更新,请对令牌调用-invalidate

    警告

    在写事务(write transaction)期间或当包含的 Realm 为只读时,无法调用此方法。

    警告

    该队列必须是串行队列。

    声明

    Objective-C

    - (nonnull RLMNotificationToken *)addNotificationBlock:
        (nonnull void (^)(id<RLMSectionedResult> _Nonnull,
                          RLMSectionedResultsChange *_Nonnull))block;

    迅速

    func addNotificationBlock(_ block: @escaping (any RLMSectionedResult, RLMSectionedResultsChange) -> Void) -> RLMNotificationToken

    参数

    block

    发生更改时要调用的区块。

    返回值

    只要您希望传递更新,就必须持有的令牌。

  • 注册一个区块,以便在每次collection更改时调用。

    该区块将与初始分段结果集合一起异步调用,然后在每次写入事务后再次调用,这会更改结果中的任何对象或结果中的对象。

    首次调用该区块时, change参数将为nil 。 对于此后的每次调用,它将包含有关在该部分中添加、删除或修改了哪些行的信息。 如果写事务未修改该部分中的任何对象,则根本不会调用该区块。 有关如何报告更改的信息以及更新UITableView的示例,请参阅RLMSectionedResultsChange文档。

    调用该区块时, RLMSection / RLMSectionedResults对象将被全面评估并保持最新状态。

    通知是通过标准事件循环传递的,因此当事件循环被其他活动阻止时无法传递。当无法立即传递通知时,可以将多个通知合并为一个通知。 这可以包括带有初始结果的通知。 例如,以下代码在添加通知块后立即执行写事务(write transaction),因此没有机会首先传递初始通知。因此,初始通知将反映写事务(write transaction)后 Realm 的状态。

    RLMResults *results = [Dog allObjects]; RLMectionedResults *sectionedResults = [results sectionedResultsUsingKeyPath:@“age” ascending:YES]; self.token = [sectionedResults addNotificationBlock:^(RLMSectionedResults *sectionedResults, RLMSectionedResultsChange *changes) { // 仅对示例触发一次 NSLog(@“sectionedResults.count: %zu”, sectionedResults.count); // => 1 }]; [realm transactionWithBlock:^{ Dog *dog = [[Dog alloc] init]; dog.name = @“Rex”; dog.age = 5 ; [realm addObject:dog]; }]; // 运行循环执行上下文结束

    只要您希望继续将更新发送到区块,就必须保留返回的令牌。 要停止接收更新,请对令牌调用-invalidate

    警告

    在写事务(write transaction)期间或当包含的 Realm 为只读时,无法调用此方法。

    警告

    该队列必须是串行队列。

    声明

    Objective-C

    - (nonnull RLMNotificationToken *)
        addNotificationBlock:
            (nonnull void (^)(id<RLMSectionedResult> _Nonnull,
                              RLMSectionedResultsChange *_Nonnull))block
                       queue:(nonnull dispatch_queue_t)queue;

    迅速

    func addNotificationBlock(_ block: @escaping (any RLMSectionedResult, RLMSectionedResultsChange) -> Void, queue: dispatch_queue_t) -> RLMNotificationToken

    参数

    block

    发生更改时要调用的区块。

    queue

    要向其传递通知的串行队列。

    返回值

    只要您希望传递更新,就必须持有的令牌。

  • 注册一个区块,以便在每次collection更改时调用。

    该区块将与初始分段结果集合一起异步调用,然后在每次写入事务后再次调用,这会更改结果中的任何对象或结果中的对象。

    首次调用该区块时, change参数将为nil 。 对于此后的每次调用,它将包含有关在该部分中添加、删除或修改了哪些行的信息。 如果写事务未修改该部分中的任何对象,则根本不会调用该区块。 有关如何报告更改的信息以及更新UITableView的示例,请参阅RLMSectionedResultsChange文档。

    调用该区块时, RLMSection / RLMSectionedResults对象将被全面评估并保持最新状态。

    通知是通过标准事件循环传递的,因此当事件循环被其他活动阻止时无法传递。当无法立即传递通知时,可以将多个通知合并为一个通知。 这可以包括带有初始结果的通知。 例如,以下代码在添加通知块后立即执行写事务(write transaction),因此没有机会首先传递初始通知。因此,初始通知将反映写事务(write transaction)后 Realm 的状态。

    RLMResults *results = [Dog allObjects]; RLMectionedResults *sectionedResults = [results sectionedResultsUsingKeyPath:@“age” ascending:YES]; self.token = [sectionedResults addNotificationBlock:^(RLMSectionedResults *sectionedResults, RLMSectionedResultsChange *changes) { // 仅对示例触发一次 NSLog(@“sectionedResults.count: %zu”, sectionedResults.count); // => 1 }]; [realm transactionWithBlock:^{ Dog *dog = [[Dog alloc] init]; dog.name = @“Rex”; dog.age = 5 ; [realm addObject:dog]; }]; // 运行循环执行上下文结束

    只要您希望继续将更新发送到区块,就必须保留返回的令牌。 要停止接收更新,请对令牌调用-invalidate

    警告

    在写事务(write transaction)期间或当包含的 Realm 为只读时,无法调用此方法。

    警告

    该队列必须是串行队列。

    声明

    Objective-C

    - (nonnull RLMNotificationToken *)
        addNotificationBlock:
            (nonnull void (^)(id<RLMSectionedResult> _Nonnull,
                              RLMSectionedResultsChange *_Nonnull))block
                    keyPaths:(nonnull NSArray<NSString *> *)keyPaths;

    迅速

    func addNotificationBlock(_ block: @escaping (any RLMSectionedResult, RLMSectionedResultsChange) -> Void, keyPaths: [String]) -> RLMNotificationToken

    参数

    block

    发生更改时要调用的区块。

    keyPaths

    这些键路径上发生的更改将调用该区块。 如果未给出键路径,则为每个属性键路径传递通知。

    返回值

    只要您希望传递更新,就必须持有的令牌。

  • 注册一个区块,以便在每次collection更改时调用。

    该区块将与初始分段结果集合一起异步调用,然后在每次写入事务后再次调用,这会更改结果中的任何对象或结果中的对象。

    首次调用该区块时, change参数将为nil 。 对于此后的每次调用,它将包含有关在该部分中添加、删除或修改了哪些行的信息。 如果写事务未修改该部分中的任何对象,则根本不会调用该区块。 有关如何报告更改的信息以及更新UITableView的示例,请参阅RLMSectionedResultsChange文档。

    调用该区块时, RLMSection / RLMSectionedResults对象将被全面评估并保持最新状态。

    通知是通过标准事件循环传递的,因此当事件循环被其他活动阻止时无法传递。当无法立即传递通知时,可以将多个通知合并为一个通知。 这可以包括带有初始结果的通知。 例如,以下代码在添加通知块后立即执行写事务(write transaction),因此没有机会首先传递初始通知。因此,初始通知将反映写事务(write transaction)后 Realm 的状态。

    RLMResults *results = [Dog allObjects]; RLMectionedResults *sectionedResults = [results sectionedResultsUsingKeyPath:@“age” ascending:YES]; self.token = [sectionedResults addNotificationBlock:^(RLMSectionedResults *sectionedResults, RLMSectionedResultsChange *changes) { // 仅对示例触发一次 NSLog(@“sectionedResults.count: %zu”, sectionedResults.count); // => 1 }]; [realm transactionWithBlock:^{ Dog *dog = [[Dog alloc] init]; dog.name = @“Rex”; dog.age = 5 ; [realm addObject:dog]; }]; // 运行循环执行上下文结束

    只要您希望继续将更新发送到区块,就必须保留返回的令牌。 要停止接收更新,请对令牌调用-invalidate

    警告

    在写事务(write transaction)期间或当包含的 Realm 为只读时,无法调用此方法。

    警告

    该队列必须是串行队列。

    注意

    使用键路径筛选时,在以下情况下会触发通知:

    • 已在筛选的属性中修改集合中的对象。
    • 已在部分键路径属性上修改对象,该修改的结果已更改其在部分中的位置,或者该对象可能需要移动到另一个部分。
    • 已在 Realm 中插入或删除观察到的相同类型的对象。

    声明

    Objective-C

    - (nonnull RLMNotificationToken *)
        addNotificationBlock:
            (nonnull void (^)(id<RLMSectionedResult> _Nonnull,
                              RLMSectionedResultsChange *_Nonnull))block
                    keyPaths:(nullable NSArray<NSString *> *)keyPaths
                       queue:(nullable dispatch_queue_t)queue;

    迅速

    func addNotificationBlock(_ block: @escaping (any RLMSectionedResult, RLMSectionedResultsChange) -> Void, keyPaths: [String]?, queue: dispatch_queue_t?) -> RLMNotificationToken

    参数

    block

    发生更改时要调用的区块。

    keyPaths

    这些键路径上发生的更改将调用该区块。 如果未给出键路径,则为每个属性键路径传递通知。

    queue

    要向其传递通知的串行队列。

    返回值

    只要您希望传递更新,就必须持有的令牌。