的協議,我有以下的模型,我使用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>
,但那也沒用。誰能告訴我我做錯了什麼?
UPDATE:
下面是該模型的另一個版本,我曾嘗試:
@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 NSNumber * routineId;'? NSNumber是一個對象指針,所以你需要c風格的'*'對象解引用。 – fullofsquirrels
@fullofsquirrels是的,我已經嘗試過。 – BlackHatSamurai
仔細看看這個,我不認爲你可以在objective-c中的'NSNumber'上使用像''這樣的泛型類型註釋;只支持像NSArray和NSDictionary這樣的集合。你可以嘗試直接聲明你的屬性爲一個非類型化的'NSNumber':'@property NSNumber * routineId;'。 –
fullofsquirrels