如何获取添加到领域的对象
我使用以下代码添加领域:
-(void) onLikeClick:(id *)sender{
NSLog(@"like btn clicked");
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
StickerModel *sticker = [[StickerModel alloc]initWithImagePath:imagePath];
sticker.imagePath = imagePath;
[realm addObject:sticker];
[realm commitWriteTransaction];
}
并希望了解{/ 1}}与
添加的对象数量realm
要获取特定索引的特定项目,我可以将其用作- (NSInteger) collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{
return [realm accessibilityElementCount];
}
但是如何?谢谢
,没有找到任何领域的api答案 0 :(得分:1)
对于计数:
RLMResults<StickerModel *> *stickers = [StickerModel allObjects];
return stickers.count;
要获取特定索引的对象,最好从已排序的集合中获取它:
RLMResults<StickerModel *> *stickers = [[StickerModel allObjects] sortedResultsUsingKeyPath:@"ID or another field" ascending:YES];
return stickers[indexPath.row];
答案 1 :(得分:0)
尝试使用它,它将提供RealM DB中的所有对象..
RLMResults * tableDataArray= [YourDB allObjects];
NSArray *peopleObjects = [tableDataArray valueForKey:@"self"];