Ios 域使用目标C添加对象
如何获取添加到领域的对象 我使用以下代码添加领域:Ios 域使用目标C添加对象,ios,objective-c,realm,Ios,Objective C,Realm,如何获取添加到领域的对象 我使用以下代码添加领域: -(void) onLikeClick:(id *)sender{ NSLog(@"like btn clicked"); RLMRealm *realm = [RLMRealm defaultRealm]; [realm beginWriteTransaction]; StickerModel *sticker = [[StickerModel alloc]initWithImagePath:imagePat
-(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];
}
想知道有多少对象被添加到领域
- (NSInteger) collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{
return [realm accessibilityElementCount];
}
并获取特定索引中的特定项,以便将其用作collectionViewDataResource
但是怎么做呢?没有找到任何领域的api,谢谢尝试使用它,它将提供领域数据库中的所有对象
RLMResults * tableDataArray= [YourDB allObjects];
NSArray *peopleObjects = [tableDataArray valueForKey:@"self"];
计数:
RLMResults<StickerModel *> *stickers = [StickerModel allObjects];
return stickers.count;
RLMResults*贴纸=[贴纸模型所有对象];
返回贴纸。计数;
要获取特定索引的对象,最好从已排序的集合中获取:
RLMResults<StickerModel *> *stickers = [[StickerModel allObjects] sortedResultsUsingKeyPath:@"ID or another field" ascending:YES];
return stickers[indexPath.row];
RLMResults*stickers=[[StickerModel allObjects]sortedResultsUsingKeyPath:@“ID或其他字段”升序:YES];
返回贴纸[indexPath.row];