RLMProperty_Private.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 RLMPropertyTypeLinkingObjects:
  46. return @"linking objects";
  47. }
  48. return @"Unknown";
  49. }
  50. // private property interface
  51. @interface RLMProperty () {
  52. @public
  53. RLMPropertyType _type;
  54. Ivar _swiftIvar;
  55. }
  56. - (instancetype)initWithName:(NSString *)name
  57. indexed:(BOOL)indexed
  58. linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
  59. property:(objc_property_t)property;
  60. - (instancetype)initSwiftPropertyWithName:(NSString *)name
  61. indexed:(BOOL)indexed
  62. linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
  63. property:(objc_property_t)property
  64. instance:(RLMObjectBase *)objectInstance;
  65. - (instancetype)initSwiftListPropertyWithName:(NSString *)name
  66. instance:(id)object;
  67. - (instancetype)initSwiftOptionalPropertyWithName:(NSString *)name
  68. indexed:(BOOL)indexed
  69. ivar:(Ivar)ivar
  70. propertyType:(RLMPropertyType)propertyType;
  71. - (instancetype)initSwiftLinkingObjectsPropertyWithName:(NSString *)name
  72. ivar:(Ivar)ivar
  73. objectClassName:(nullable NSString *)objectClassName
  74. linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName;
  75. // private setters
  76. @property (nonatomic, readwrite) NSString *name;
  77. @property (nonatomic, readwrite, assign) RLMPropertyType type;
  78. @property (nonatomic, readwrite) BOOL indexed;
  79. @property (nonatomic, readwrite) BOOL optional;
  80. @property (nonatomic, copy, nullable) NSString *objectClassName;
  81. // private properties
  82. @property (nonatomic, readwrite) NSString *columnName;
  83. @property (nonatomic, assign) NSUInteger index;
  84. @property (nonatomic, assign) BOOL isPrimary;
  85. @property (nonatomic, assign) Ivar swiftIvar;
  86. // getter and setter names
  87. @property (nonatomic, copy) NSString *getterName;
  88. @property (nonatomic, copy) NSString *setterName;
  89. @property (nonatomic) SEL getterSel;
  90. @property (nonatomic) SEL setterSel;
  91. - (RLMProperty *)copyWithNewName:(NSString *)name;
  92. @end
  93. @interface RLMProperty (Dynamic)
  94. /**
  95. This method is useful only in specialized circumstances, for example, in conjunction with
  96. +[RLMObjectSchema initWithClassName:objectClass:properties:]. If you are simply building an
  97. app on Realm, it is not recommened to use this method.
  98. Initialize an RLMProperty
  99. @warning This method is useful only in specialized circumstances.
  100. @param name The property name.
  101. @param type The property type.
  102. @param objectClassName The object type used for Object and Array types.
  103. @param linkOriginPropertyName The property name of the origin of a link. Used for linking objects properties.
  104. @return An initialized instance of RLMProperty.
  105. */
  106. - (instancetype)initWithName:(NSString *)name
  107. type:(RLMPropertyType)type
  108. objectClassName:(nullable NSString *)objectClassName
  109. linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName
  110. indexed:(BOOL)indexed
  111. optional:(BOOL)optional;
  112. @end
  113. NS_ASSUME_NONNULL_END