added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / RLMProperty_Private.h
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
19 #import <Realm/RLMProperty.h>
20
21 #import <objc/runtime.h>
22
23 @class RLMObjectBase;
24
25 NS_ASSUME_NONNULL_BEGIN
26
27 BOOL RLMPropertyTypeIsComputed(RLMPropertyType propertyType);
28 FOUNDATION_EXTERN void RLMValidateSwiftPropertyName(NSString *name);
29
30 // Translate an rlmtype to a string representation
31 static inline NSString *RLMTypeToString(RLMPropertyType type) {
32     switch (type) {
33         case RLMPropertyTypeString:
34             return @"string";
35         case RLMPropertyTypeInt:
36             return @"int";
37         case RLMPropertyTypeBool:
38             return @"bool";
39         case RLMPropertyTypeDate:
40             return @"date";
41         case RLMPropertyTypeData:
42             return @"data";
43         case RLMPropertyTypeDouble:
44             return @"double";
45         case RLMPropertyTypeFloat:
46             return @"float";
47         case RLMPropertyTypeAny:
48             return @"any";
49         case RLMPropertyTypeObject:
50             return @"object";
51         case RLMPropertyTypeLinkingObjects:
52             return @"linking objects";
53     }
54     return @"Unknown";
55 }
56
57 // private property interface
58 @interface RLMProperty () {
59 @public
60     RLMPropertyType _type;
61     Ivar _swiftIvar;
62 }
63
64 - (instancetype)initWithName:(NSString *)name
65                      indexed:(BOOL)indexed
66       linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
67                     property:(objc_property_t)property;
68
69 - (instancetype)initSwiftPropertyWithName:(NSString *)name
70                                   indexed:(BOOL)indexed
71                    linkPropertyDescriptor:(nullable RLMPropertyDescriptor *)linkPropertyDescriptor
72                                  property:(objc_property_t)property
73                                  instance:(RLMObjectBase *)objectInstance;
74
75 - (instancetype)initSwiftListPropertyWithName:(NSString *)name
76                                      instance:(id)object;
77
78 - (instancetype)initSwiftOptionalPropertyWithName:(NSString *)name
79                                           indexed:(BOOL)indexed
80                                              ivar:(Ivar)ivar
81                                      propertyType:(RLMPropertyType)propertyType;
82
83 - (instancetype)initSwiftLinkingObjectsPropertyWithName:(NSString *)name
84                                                    ivar:(Ivar)ivar
85                                         objectClassName:(nullable NSString *)objectClassName
86                                  linkOriginPropertyName:(nullable NSString *)linkOriginPropertyName;
87
88 // private setters
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;
94
95 // private properties
96 @property (nonatomic, assign) NSUInteger index;
97 @property (nonatomic, assign) BOOL isPrimary;
98 @property (nonatomic, assign) Ivar swiftIvar;
99
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;
105
106 - (RLMProperty *)copyWithNewName:(NSString *)name;
107
108 @end
109
110 @interface RLMProperty (Dynamic)
111 /**
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.
115
116  Initialize an RLMProperty
117
118  @warning This method is useful only in specialized circumstances.
119
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.
124
125  @return    An initialized instance of RLMProperty.
126  */
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;
133 @end
134
135 NS_ASSUME_NONNULL_END