领域错误:属性需要定义所包含类型的协议 [英] Realm Error: Property requires a protocol defining the contained type
问题描述
我有以下模型,正在使用Realm
:
I have the following model and I'm using 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>
,但这也不起作用.谁能告诉我我在做什么错?
I have tried changing the routineId
property to NSNumber<RLMint>
, but that didn't work either. Can anyone tell me what I'm doing wrong?
更新:
这是我尝试过的模型的另一个版本:
Here is another version of the model that I have tried:
@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
推荐答案
Property requires a protocol defining the contained type error
仅由Realm针对类型为NSNumber
的属性生成,而没有协议注释预期的具体类型.这意味着不能为您提到的任何一个模型类生成它.您的应用程序其他位置可能还有另一个routineId
属性,该属性会触发错误.
The Property requires a protocol defining the contained type error
is only generated by Realm for a property of type NSNumber
without a protocol annotating the expected concrete type. That means it cannot be generated for either of the model classes you mention. It's likely you have a another routineId
property elsewhere in your app that is triggering the error.
这篇关于领域错误:属性需要定义所包含类型的协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!