RLMProperty_Private.h 5.1 KB

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