领域错误:属性需要一个定义包含类型的协议

时间:2016-04-25 21:50:54

标签: ios objective-c realm

我有以下模型,我正在使用Realm

@interface GUIRoutineModel : GUIModel # GUIModel is a subclass of RLMObject

@property (nonatomic, retain) NSString *dateCreated;
@property (nonatomic, retain) NSString *dateModified;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *type;

@property NSInteger userId;
@property int routineId; #also have same issue using NSInteger


@end

我打电话的时候:

   // Persist to Realm DB
    RLMRealm *realm = [RLMRealm defaultRealm];
    [realm transactionWithBlock:^{
        [realm addObject:routineModel];
    }];

我收到以下错误:

'Property 'routineId' requires a protocol defining the contained type - example: NSNumber<RLMInt>.'

我尝试将routineId属性更改为NSNumber<RLMint>,但这也无效。谁能告诉我我做错了什么?

更新:

这是我尝试的另一个版本的模型:

@interface GUIRoutineModel : GUIModel

@property (nonatomic, retain) NSString *dateCreated;
@property (nonatomic, retain) NSString *dateModified;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *type;

@property NSInteger userId;
@property NSNumber<RLMInt> *routineId;

@end

1 个答案:

答案 0 :(得分:6)

Property requires a protocol defining the contained type error仅由Realm为NSNumber类型的属性生成,没有协议注释预期的具体类型。这意味着无法为您提到的任何一个模型类生成它。您可能在应用中的其他地方有另一个routineId属性触发了错误。