具有主键的 RLMObject 基本模型类 - Objective-C
使用主键和一些通用默认属性的 RLMObject 基本模型类的示例。然后,子类可以设置特定于其需求的元数据。
@interface BaseModel : RLMObject
@property NSString *uuid;
@property NSString *metadata;
@end
@implementation BaseModel
+ (NSString *)primaryKey
{
return @"uuid";
}
+ (NSDictionary *)defaultPropertyValues
{
NSMutableDictionary *defaultPropertyValues = [NSMutableDictionary dictionaryWithDictionary:[super defaultPropertyValues]];
NSString *uuid = [[NSUUID UUID] UUIDString];
[defaultPropertyValues setValue:@"" forKey:@"metadata"];
[defaultPropertyValues setValue:uuid forKey:@"uuid"];
return defaultPropertyValues;
}
+ (NSArray *)ignoredProperties
{
return @[];
}
@end