RLMValue
Objective-C
@protocol RLMValue
Swift
protocol RLMValue
RLMValue 是一种表示多态 Realm 值的属性类型。 这类似于 Swift 中AnyObject
/ Any
的用法。
// A property on `MyObject`
@property (nonatomic) id<RLMValue> myAnyValue;
// A property on `AnotherObject`
@property (nonatomic) id<RLMValue> myAnyValue;
MyObject *myObject = [MyObject createInRealm:realm withValue:@[]];
myObject.myAnyValue = @1234; // underlying type is NSNumber.
myObject.myAnyValue = @"hello"; // underlying type is NSString.
AnotherObject *anotherObject = [AnotherObject createInRealm:realm withValue:@[]];
myObject.myAnyValue = anotherObject; // underlying type is RLMObject.
以下类型符合 RLMValue:
NSData
NSDate
NSNull
NSNumber
NSUUID
NSString
RLMObject
RLMObjectId
RLMDecimal 128
RLMDictionary
RLMArray
NSArray
NSDictionary`
-
已弃用
请改用
rlm_anyValueType
,其中还包括集合类型描述存储的属性的类型。
声明
Objective-C
@property (readonly) RLMAnyValueType rlm_valueType;
Swift
var rlm_valueType: RLMAnyValueType { get }
-
描述存储的属性的类型。
声明
Objective-C
@property (readonly) RLMAnyValueType rlm_anyValueType;
Swift
var rlm_anyValueType: RLMAnyValueType { get }