RLMSyncPermissionResults.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2017 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. #import "RLMSyncUser.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. /// Properties which a sync permission results collection can be sorted by.
  22. typedef NS_ENUM(NSUInteger, RLMSyncPermissionResultsSortProperty) {
  23. /// Sort by the Realm Object Server path to the Realm to which the permission applies.
  24. RLMSyncPermissionResultsSortPropertyPath,
  25. /// Sort by the identity of the user to whom the permission applies.
  26. RLMSyncPermissionResultsSortPropertyUserID,
  27. /// Sort by the date the permissions were last updated.
  28. RLMSyncPermissionResultsSortDateUpdated,
  29. };
  30. @class RLMSyncPermissionValue, RLMNotificationToken;
  31. /**
  32. A collection object representing the results of a permissions query.
  33. This collection will automatically update its contents at the start of each runloop
  34. iteration, but the objects it vends are immutable.
  35. Permission results objects are thread-confined, and should not be shared across
  36. threads.
  37. @warning Permission results must only be fetched on threads that have an active
  38. run loop. In most cases this will be the main thread.
  39. */
  40. @interface RLMSyncPermissionResults : NSObject<NSFastEnumeration>
  41. /// The number of results contained within the object.
  42. @property (nonatomic, readonly) NSInteger count;
  43. /**
  44. Return the first permission, or nil if the collection is empty.
  45. */
  46. - (nullable RLMSyncPermissionValue *)firstObject NS_SWIFT_UNAVAILABLE("Use the `first` property.");
  47. /**
  48. Return the last permission, or nil if the collection is empty.
  49. */
  50. - (nullable RLMSyncPermissionValue *)lastObject NS_SWIFT_UNAVAILABLE("Use the `last` property.");
  51. /**
  52. Retrieve the permission value at the given index. Throws an exception if the index
  53. is out of bounds.
  54. */
  55. - (RLMSyncPermissionValue *)objectAtIndex:(NSInteger)index;
  56. /**
  57. Returns the index of the permission in the collection, or `NSNotFound` if the permission
  58. is not found in the collection.
  59. */
  60. - (NSInteger)indexOfObject:(RLMSyncPermissionValue *)object;
  61. /**
  62. Register to be notified when the contents of the results object change.
  63. This method returns a token. Hold on to the token for as long as notifications
  64. are desired. Call `-stop` on the token to stop notifications, and before
  65. deallocating the token.
  66. */
  67. - (RLMNotificationToken *)addNotificationBlock:(RLMPermissionStatusBlock)block;
  68. #pragma mark - Queries
  69. /**
  70. Return all permissions matching the given predicate in the collection.
  71. @note Valid properties to filter on are `path` and `userId`, as well as
  72. the boolean properties `mayRead`, `mayWrite`, and `mayManage`.
  73. */
  74. - (RLMSyncPermissionResults *)objectsWithPredicate:(NSPredicate *)predicate;
  75. /**
  76. Return a sorted `RLMSyncPermissionResults` from the collection, sorted based on
  77. the given property.
  78. */
  79. - (RLMSyncPermissionResults *)sortedResultsUsingProperty:(RLMSyncPermissionResultsSortProperty)property
  80. ascending:(BOOL)ascending;
  81. #pragma mark - Misc
  82. /// :nodoc:
  83. - (instancetype)init __attribute__((unavailable("RLMSyncPermissionResults cannot be created directly")));
  84. /// :nodoc:
  85. + (instancetype)new __attribute__((unavailable("RLMSyncPermissionResults cannot be created directly")));
  86. @end
  87. NS_ASSUME_NONNULL_END