ios - NSFetchedResultsController - how to handle changing Core Data source? -


i'm using core data magicalrecord , nsfetchedresultscontroller display data in table view. works fine, have change underlying sqlite-file underneath leads crash.

i'm creating frc following way:

nsfetchrequest *request = [nsfetchrequest fetchrequestwithentityname:@"cdperson"]; nssortdescriptor *sortbynamedescriptor = [nssortdescriptor sortdescriptorwithkey:@"lastname" ascending:yes]; request.sortdescriptors = @[sortbynamedescriptor]; _fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:request managedobjectcontext:[nsmanagedobjectcontext mr_contextforcurrentthread] sectionnamekeypath:nil cachename:nil]; _fetchedresultscontroller.delegate = self; [_fetchedresultscontroller performfetch:nil]; 

when changing sqlite-file, i'm doing:

[magicalrecord cleanup]; // delete old sqlite file // copy new sqlite file [magicalrecord setupcoredatastackwithautomigratingsqlitestorenamed:sqlite_filename]; 

what have frc have take new storage? create new 1 seems not enough crash in

- (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller {     [[self tableview] endupdates]; } 

how can achieve this?

edit

@question flexaddicted: error i'm getting in endupdates assertion failure in -[uitableview _endcellanimationswithcontext:]

@question exploring: can imagine i've got 2 sqlite files i'm exchanging - both same tables, different content. frc shows content of first file, i'd cleanup magicalrecord, let point other store , 'refresh' frc.

you need tear down , restart. once have recreated core data stack need recreate frc new context , reloaddata on table view (you can't reload rows because backing data has changed).


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -