- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
self.savedSearchTerm = searchText;
__weak FormEntryListViewController *weakSelf = self;
[self.searchQueue cancelAllOperations];
[self.searchQueue addOperationWithBlock:^{
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf displayLoadingHud];
});
// Ensure you're assigning to a local variable here.
// Do not assign to a member variable. You will get
// occasional thread race condition related crashes
// if you do.
NSMutableDictionary *results = [weakSelf freshFormEntries];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// Modify your instance variables here on the main
// UI thread.
[weakSelf.formEntries removeAllObjects];
[weakSelf.formEntries addEntriesFromDictionary:results];
[weakSelf loadRecords];
[MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
}];
}];
}
On Aug 31, 2016, at 1:00 PM, Brendan Duddridge <bren...@gmail.com> wrote:The only thing I can think of is fetching document IDs from the search results, then fetching again all of the model objects for those IDs in one big fetch. The problem with this is there could potentially be thousands of results and now I'm fetching twice.
However, this technique doesn't really work with Couchbase Lite because I cannot access the model objects on the main thread those objects that I fetched on the background thread using the NSOperationQueue.