RLMObject_Private.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. NS_ASSUME_NONNULL_BEGIN
  20. // RLMObject accessor and read/write realm
  21. @interface RLMObjectBase () {
  22. @public
  23. RLMRealm *_realm;
  24. __unsafe_unretained RLMObjectSchema *_objectSchema;
  25. }
  26. // unmanaged initializer
  27. - (instancetype)initWithValue:(id)value schema:(RLMSchema *)schema NS_DESIGNATED_INITIALIZER;
  28. // live accessor initializer
  29. - (instancetype)initWithRealm:(__unsafe_unretained RLMRealm *const)realm
  30. schema:(RLMObjectSchema *)schema NS_DESIGNATED_INITIALIZER;
  31. // shared schema for this class
  32. + (nullable RLMObjectSchema *)sharedSchema;
  33. // provide injection point for alternative Swift object util class
  34. + (Class)objectUtilClass:(BOOL)isSwift;
  35. @end
  36. @interface RLMObject ()
  37. // unmanaged initializer
  38. - (instancetype)initWithValue:(id)value schema:(RLMSchema *)schema NS_DESIGNATED_INITIALIZER;
  39. // live accessor initializer
  40. - (instancetype)initWithRealm:(__unsafe_unretained RLMRealm *const)realm
  41. schema:(RLMObjectSchema *)schema NS_DESIGNATED_INITIALIZER;
  42. @end
  43. @interface RLMDynamicObject : RLMObject
  44. @end
  45. // A reference to an object's row that doesn't keep the object accessor alive.
  46. // Used by some Swift property types, such as LinkingObjects, to avoid retain cycles
  47. // with their containing object.
  48. @interface RLMWeakObjectHandle : NSObject<NSCopying>
  49. - (instancetype)initWithObject:(RLMObjectBase *)object;
  50. // Consumes the row, so can only usefully be called once.
  51. @property (nonatomic, readonly) RLMObjectBase *object;
  52. @end
  53. // Calls valueForKey: and re-raises NSUndefinedKeyExceptions
  54. FOUNDATION_EXTERN id _Nullable RLMValidatedValueForProperty(id object, NSString *key, NSString *className);
  55. // Compare two RLObjectBases
  56. FOUNDATION_EXTERN BOOL RLMObjectBaseAreEqual(RLMObjectBase * _Nullable o1, RLMObjectBase * _Nullable o2);
  57. typedef void (^RLMObjectNotificationCallback)(NSArray<NSString *> *_Nullable propertyNames,
  58. NSArray *_Nullable oldValues,
  59. NSArray *_Nullable newValues,
  60. NSError *_Nullable error);
  61. FOUNDATION_EXTERN RLMNotificationToken *RLMObjectAddNotificationBlock(RLMObjectBase *obj, RLMObjectNotificationCallback block);
  62. // Returns whether the class is a descendent of RLMObjectBase
  63. FOUNDATION_EXTERN BOOL RLMIsObjectOrSubclass(Class klass);
  64. // Returns whether the class is an indirect descendant of RLMObjectBase
  65. FOUNDATION_EXTERN BOOL RLMIsObjectSubclass(Class klass);
  66. // For unit testing purposes, allow an Objective-C class named FakeObject to also be used
  67. // as the base class of managed objects. This allows for testing invalid schemas.
  68. FOUNDATION_EXTERN void RLMSetTreatFakeObjectAsRLMObject(BOOL flag);
  69. // Get ObjectUil class for objc or swift
  70. FOUNDATION_EXTERN Class RLMObjectUtilClass(BOOL isSwift);
  71. FOUNDATION_EXTERN const NSUInteger RLMDescriptionMaxDepth;
  72. @class RLMProperty, RLMArray;
  73. @interface RLMObjectUtil : NSObject
  74. + (nullable NSArray<NSString *> *)ignoredPropertiesForClass:(Class)cls;
  75. + (nullable NSArray<NSString *> *)indexedPropertiesForClass:(Class)cls;
  76. + (nullable NSDictionary<NSString *, NSDictionary<NSString *, NSString *> *> *)linkingObjectsPropertiesForClass:(Class)cls;
  77. + (nullable NSArray<NSString *> *)getGenericListPropertyNames:(id)obj;
  78. + (nullable NSDictionary<NSString *, NSDictionary<NSString *, NSString *> *> *)getLinkingObjectsProperties:(id)object;
  79. + (nullable NSDictionary<NSString *, NSNumber *> *)getOptionalProperties:(id)obj;
  80. + (nullable NSArray<NSString *> *)requiredPropertiesForClass:(Class)cls;
  81. @end
  82. NS_ASSUME_NONNULL_END