Realm Error: Property requires a protocol defining the contained type

怎甘沉沦 提交于 2019-12-12 13:03:45

问题


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

When I call:

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

I get the following error:

'Property 'routineId' requires a protocol defining the contained type - example: 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?

UPDATE:

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

回答1:


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.



来源:https://stackoverflow.com/questions/36851728/realm-error-property-requires-a-protocol-defining-the-contained-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!