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`