Does YapDatabase have an equivalent to NSFetchedResultsController indexPathForObject:?

339 Views Asked by At

I have a UITableView that uses a YapDatabaseView and a YapDatabaseViewMappings. I am trying to programmatically have my table view scroll to the position of a given object in the database...

With CoreData I was doing:

NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:myObject];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

Any equivalent to that scenario with YapDatabase?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes it does. You can use the API indexPathForKey(:inCollection:withMappings) which is available on YapDatabaseViewTransaction.

e.g.

YapDatabaseViewTransaction *viewTransaction = [transaction ext:"view name"];
NSIndexPath *indexPath = [viewTransaction indexPathForKey(myObject.key, inCollection: myObject.collection, withMappings: mappings];

This assumes that you can access the key and collection from your object.

If you're using Swift, then check out TaylorSource which makes this a doddle.