RLMProperty_Private.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/RLMProperty.h>
  19. #import <objc/runtime.h>
  20. @class RLMObjectBase;
  21. NS_ASSUME_NONNULL_BEGIN
  22. BOOL RLMPropertyTypeIsComputed(RLMPropertyType propertyType);
  23. FOUNDATION_EXTERN void RLMValidateSwiftPropertyName(NSString *name);
  24. // Translate an rlmtype to a string representation
  25. static inline NSString *RLMTypeToString(RLMPropertyType type) {
  26. switch (type) {
  27. case RLMPropertyTypeString:
  28. return @"string";
  29. case RLMPropertyTypeInt:
  30. return @"int";
  31. case RLMPropertyTypeBool:
  32. return @"bool";
  33. case RLMPropertyTypeDate:
  34. return @"date";
  35. case RLMPropertyTypeData:
  36. return @"data";
  37. case RLMPropertyTypeDouble:
  38. return @"double";
  39. case RLMPropertyTypeFloat:
  40. return @"float";
  41. case RLMPropertyTypeAny:
  42. return @"any";
  43. case RLMPropertyTypeObject:
  44. return @"object";
  45. case RLMPropertyTypeArray:
  46. return @"array";
  47. case RLMPropertyTypeLinkingObjects:
  48. return @"linking objects";
  49. }
  50. return @"Unknown";
  51. }
  52. // private property interface
  53. @interface RLMProperty () {
  54. @public
  55. RLMPropertyType _type;
  56. Ivar _swiftIvar;
  57. }
  58. - (instancetype)initWithName:(NSString *)name
  59. indexed:(BOOL)indexed
  60. linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
  61. property:(objc_property_t)property;
  62. - (instancetype)initSwiftPropertyWithName:(NSString *)name
  63. indexed:(BOOL)indexed
  64. linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
  65. property:(objc_property_t)property
  66. instance:(RLMObjectBase *)objectInstance;
  67. - (instancetype)initSwiftListPropertyWithName:(NSString *)name
  68. instance:(id)object;
  69. - (instancetype)initSwiftOptionalPropertyWithName:(NSString *)name
  70. indexed:(BOOL)indexed
  71. ivar:(Ivar)ivar
  72. propertyType:(RLMPropertyType)propertyType;
  73. - (instancetype)initSwiftLinkingObjectsPropertyWithName:(NSString *)name
  74. ivar:(Ivar)ivar
  75. objectClassName:(nullable NSString *)objectClassName
  76. linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName;
  77. // private setters
  78. @property (nonatomic, readwrite) NSString *name;
  79. @property (nonatomic, readwrite, assign) RLMPropertyType type;
  80. @property (nonatomic, readwrite) BOOL indexed;
  81. @property (nonatomic, readwrite) BOOL optional;
  82. @property (nonatomic, copy, nullable) NSString *objectClassName;
  83. // private properties
  84. @property (nonatomic, assign) NSUInteger index;
  85. @property (nonatomic, assign) BOOL isPrimary;
  86. @property (nonatomic, assign) Ivar swiftIvar;
  87. // getter and setter names
  88. @property (nonatomic, copy) NSString *getterName;
  89. @property (nonatomic, copy) NSString *setterName;
  90. @property (nonatomic) SEL getterSel;
  91. @property (nonatomic) SEL setterSel;
  92. - (RLMProperty *)copyWithNewName:(NSString *)name;
  93. @end
  94. @interface RLMProperty (Dynamic)
  95. /**
  96. This method is useful only in specialized circumstances, for example, in conjunction with
  97. +[RLMObjectSchema initWithClassName:objectClass:properties:]. If you are simply building an
  98. app on Realm, it is not recommened to use this method.
  99. Initialize an RLMProperty
  100. @warning This method is useful only in specialized circumstances.
  101. @param name The property name.
  102. @param type The property type.
  103. @param objectClassName The object type used for Object and Array types.
  104. @param linkOriginPropertyName The property name of the origin of a link. Used for linking objects properties.
  105. @return An initialized instance of RLMProperty.
  106. */
  107. - (instancetype)initWithName:(NSString *)name
  108. type:(RLMPropertyType)type
  109. objectClassName:(nullable NSString *)objectClassName
  110. linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName
  111. indexed:(BOOL)indexed
  112. optional:(BOOL)optional;
  113. @end
  114. NS_ASSUME_NONNULL_END