magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.79k stars 1.79k forks source link

NSArray returned by MR_findAllSortedBy will be cleared automatically #686

Open yorkwang opened 10 years ago

yorkwang commented 10 years ago

It's strange, my code is as below:

//do search
NSPredicate *predicate;
NSString *searchStr =  [NSString stringWithFormat:@"*%@*",searchText];
predicate = [NSPredicate predicateWithFormat:@"name like[cd] %@ OR author like[cd] %@ ",searchStr,searchStr];
_comicsArrayBySearch = [Comic MR_findAllSortedBy:@"name" ascending:YES withPredicate:predicate inContext:localContext];

_comicsArrayBySearch is the datasource of a tableView, after every search, the search results will be shown on the tableview, every thing is fine. But without scrolling the tableView for a while, _comicsArrayBySearch’s core data item will be cleared automatically, then scroll tableview agin, tableView's cell count is still right, but every cell is blank with no data filled. Before using MagicalRecord, the search result array wasn't cleared automatically, but MagicalRecord is really easy and excellent.

tonyarnold commented 10 years ago

Can you verify that the _comicsArrayBySearch instance variable still contains the data you expect it to?

yorkwang commented 10 years ago

Hi, tonyarnold:

Sorry for my late reply!

Here is my code,

}

If I call doSearch method in background, _comicsArrayBySearch's NsMangaObjects will be automatically cleared after a while.

NSString *searchText = searchBar.text; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self doSearch:searchText]; });

If I call doSearch method in main thread, _comicsArrayBySearch's NsMangaObjects will not be cleared.

BTW, NSFetchedResultsController is not used because I want to sort the search results in my own way.