1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2014 Realm Inc.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ////////////////////////////////////////////////////////////////////////////
19 #import <Realm/RLMProperty.h>
21 #import <objc/runtime.h>
25 NS_ASSUME_NONNULL_BEGIN
27 BOOL RLMPropertyTypeIsComputed(RLMPropertyType propertyType);
28 FOUNDATION_EXTERN void RLMValidateSwiftPropertyName(NSString *name);
30 // Translate an rlmtype to a string representation
31 static inline NSString *RLMTypeToString(RLMPropertyType type) {
33 case RLMPropertyTypeString:
35 case RLMPropertyTypeInt:
37 case RLMPropertyTypeBool:
39 case RLMPropertyTypeDate:
41 case RLMPropertyTypeData:
43 case RLMPropertyTypeDouble:
45 case RLMPropertyTypeFloat:
47 case RLMPropertyTypeAny:
49 case RLMPropertyTypeObject:
51 case RLMPropertyTypeLinkingObjects:
52 return @"linking objects";
57 // private property interface
58 @interface RLMProperty () {
60 RLMPropertyType _type;
64 - (instancetype)initWithName:(NSString *)name
66 linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
67 property:(objc_property_t)property;
69 - (instancetype)initSwiftPropertyWithName:(NSString *)name
71 linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
72 property:(objc_property_t)property
73 instance:(RLMObjectBase *)objectInstance;
75 - (instancetype)initSwiftListPropertyWithName:(NSString *)name
78 - (instancetype)initSwiftOptionalPropertyWithName:(NSString *)name
81 propertyType:(RLMPropertyType)propertyType;
83 - (instancetype)initSwiftLinkingObjectsPropertyWithName:(NSString *)name
85 objectClassName:(nullable NSString *)objectClassName
86 linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName;
89 @property (nonatomic, readwrite) NSString *name;
90 @property (nonatomic, readwrite, assign) RLMPropertyType type;
91 @property (nonatomic, readwrite) BOOL indexed;
92 @property (nonatomic, readwrite) BOOL optional;
93 @property (nonatomic, copy, nullable) NSString *objectClassName;
96 @property (nonatomic, assign) NSUInteger index;
97 @property (nonatomic, assign) BOOL isPrimary;
98 @property (nonatomic, assign) Ivar swiftIvar;
100 // getter and setter names
101 @property (nonatomic, copy) NSString *getterName;
102 @property (nonatomic, copy) NSString *setterName;
103 @property (nonatomic) SEL getterSel;
104 @property (nonatomic) SEL setterSel;
106 - (RLMProperty *)copyWithNewName:(NSString *)name;
110 @interface RLMProperty (Dynamic)
112 This method is useful only in specialized circumstances, for example, in conjunction with
113 +[RLMObjectSchema initWithClassName:objectClass:properties:]. If you are simply building an
114 app on Realm, it is not recommened to use this method.
116 Initialize an RLMProperty
118 @warning This method is useful only in specialized circumstances.
120 @param name The property name.
121 @param type The property type.
122 @param objectClassName The object type used for Object and Array types.
123 @param linkOriginPropertyName The property name of the origin of a link. Used for linking objects properties.
125 @return An initialized instance of RLMProperty.
127 - (instancetype)initWithName:(NSString *)name
128 type:(RLMPropertyType)type
129 objectClassName:(nullable NSString *)objectClassName
130 linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName
131 indexed:(BOOL)indexed
132 optional:(BOOL)optional;
135 NS_ASSUME_NONNULL_END