2017-08-12 15 views
0
#import "RLMObject.h" 

@interface Product : RLMObject 

@property NSInteger productId; 
@property NSString *name; 

@end 

@implementation Product 

+ (NSString *)primaryKey { 
    return @"productId"; 
} 

@end 

獲取所有對象:正確的方式來檢索領域數據庫中的單個對象在Objective-C

RLMResults<Product *> *xx = [Product allObjects]; 

但如何通過主鍵獲取單個對象(不是數組)?

回答

1

不限RLMObject子類繼承方法

  • (可爲空instancetype)objectForPrimaryKey:(可爲空的ID)的PrimaryKey;

所以,你可以通過調用獲取單個對象:

[Product objectForPrimaryKey: @""]; 
相關問題