RLMObject_Private.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2014 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 <Realm/RLMObjectBase_Dynamic.h>
  19. #import <Realm/RLMRealm.h>
  20. RLM_HEADER_AUDIT_BEGIN(nullability, sendability)
  21. @class RLMProperty, RLMArray, RLMSchema;
  22. typedef NS_ENUM(int32_t, RLMPropertyType);
  23. FOUNDATION_EXTERN void RLMInitializeWithValue(RLMObjectBase *, id, RLMSchema *);
  24. typedef void (^RLMObjectNotificationCallback)(RLMObjectBase *_Nullable object,
  25. NSArray<NSString *> *_Nullable propertyNames,
  26. NSArray *_Nullable oldValues,
  27. NSArray *_Nullable newValues,
  28. NSError *_Nullable error);
  29. // RLMObject accessor and read/write realm
  30. @interface RLMObjectBase () {
  31. @public
  32. RLMRealm *_realm;
  33. __unsafe_unretained RLMObjectSchema *_objectSchema;
  34. }
  35. // shared schema for this class
  36. + (nullable RLMObjectSchema *)sharedSchema;
  37. + (nullable NSArray<RLMProperty *> *)_getProperties;
  38. + (bool)_realmIgnoreClass;
  39. // This enables to override the propertiesMapping in Swift, it is not to be used in Objective-C API.
  40. + (NSDictionary<NSString *, NSString *> *)propertiesMapping;
  41. @end
  42. @interface RLMDynamicObject : RLMObject
  43. @end
  44. // Calls valueForKey: and re-raises NSUndefinedKeyExceptions
  45. FOUNDATION_EXTERN id _Nullable RLMValidatedValueForProperty(id object, NSString *key, NSString *className);
  46. // Compare two RLObjectBases
  47. FOUNDATION_EXTERN BOOL RLMObjectBaseAreEqual(RLMObjectBase * _Nullable o1, RLMObjectBase * _Nullable o2);
  48. FOUNDATION_EXTERN RLMNotificationToken *RLMObjectBaseAddNotificationBlock(RLMObjectBase *obj,
  49. NSArray<NSString *> *_Nullable keyPaths,
  50. dispatch_queue_t _Nullable queue,
  51. RLMObjectNotificationCallback block);
  52. RLMNotificationToken *RLMObjectAddNotificationBlock(RLMObjectBase *obj,
  53. RLMObjectChangeBlock block,
  54. NSArray<NSString *> *_Nullable keyPaths,
  55. dispatch_queue_t _Nullable queue);
  56. // Returns whether the class is a descendent of RLMObjectBase
  57. FOUNDATION_EXTERN BOOL RLMIsObjectOrSubclass(Class klass);
  58. // Returns whether the class is an indirect descendant of RLMObjectBase
  59. FOUNDATION_EXTERN BOOL RLMIsObjectSubclass(Class klass);
  60. FOUNDATION_EXTERN const NSUInteger RLMDescriptionMaxDepth;
  61. FOUNDATION_EXTERN id RLMObjectFreeze(RLMObjectBase *obj) NS_RETURNS_RETAINED;
  62. FOUNDATION_EXTERN id RLMObjectThaw(RLMObjectBase *obj);
  63. // Gets an object identifier suitable for use with Combine. This value may
  64. // change when an unmanaged object is added to the Realm.
  65. FOUNDATION_EXTERN uint64_t RLMObjectBaseGetCombineId(RLMObjectBase *);
  66. // An accessor object which is used to interact with Swift properties from obj-c
  67. @interface RLMManagedPropertyAccessor : NSObject
  68. // Perform any initialization required for KVO on a *unmanaged* object
  69. + (void)observe:(RLMProperty *)property on:(RLMObjectBase *)parent;
  70. // Initialize the given property on a *managed* object which previous was unmanaged
  71. + (void)promote:(RLMProperty *)property on:(RLMObjectBase *)parent;
  72. // Initialize the given property on a newly created *managed* object
  73. + (void)initialize:(RLMProperty *)property on:(RLMObjectBase *)parent;
  74. // Read the value of the property, on either kind of object
  75. + (id)get:(RLMProperty *)property on:(RLMObjectBase *)parent;
  76. // Set the property to the given value, on either kind of object
  77. + (void)set:(RLMProperty *)property on:(RLMObjectBase *)parent to:(id)value;
  78. @end
  79. @interface RLMObjectNotificationToken : RLMNotificationToken
  80. - (void)observe:(RLMObjectBase *)obj
  81. keyPaths:(nullable NSArray<NSString *> *)keyPaths
  82. block:(RLMObjectNotificationCallback)block;
  83. - (void)registrationComplete:(void (^)(void))completion;
  84. @end
  85. RLM_HEADER_AUDIT_END(nullability, sendability)