2016-04-25 84 views
2

的協議,我有以下的模型,我使用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 
+0

你試過這個:'@property NSNumber * routineId;'? NSNumber是一個對象指針,所以你需要c風格的'*'對象解引用。 – fullofsquirrels

+0

@fullofsquirrels是的,我已經嘗試過。 – BlackHatSamurai

+0

仔細看看這個,我不認爲你可以在objective-c中的'NSNumber'上使用像''這樣的泛型類型註釋;只支持像NSArray和NSDictionary這樣的集合。你可以嘗試直接聲明你的屬性爲一個非類型化的'NSNumber':'@property NSNumber * routineId;'。 – fullofsquirrels

回答

6

Property requires a protocol defining the contained type error僅由域生成NSNumber類型的屬性,而不使用協議來註釋預期的具體類型。這意味着它不能爲您提到的任何模型類生成。很可能你的應用程序中的其他地方有另一個routineId屬性,這是觸發錯誤的原因。

+1

這是不正確的。我檢查了應用程序中是否有相同的屬性或其他應用程序中的其他屬性。我沒有其他財產,但仍然面臨錯誤。 – user3182143

相關問題