iphone - What should I watch to debug this Core-Data / NSFetchedResultsController bug? -
i've got bug in core data implementation cannot seem hold of, , need tips on should looking figure out how fix it.
to make long story short, have uitableview
being populated nsfetchedresultscontroller
. want users able change sorting options data, give them picker change underlying fetchedresultscontroller
different preset configurations. can change , forth between different fetchedresultscontrollers
no issue whatsoever. can add , remove data, never experiencing crashes, no problem. however, on 2 (out of 6, , same 2) of fetchedresultcontroller
configurations, items added database not added tableview. , items in tableview disappear once edited.
here steps go through reproduce bug:
- set sorting configuration works
- add new item database (at point
controllerwillchangecontent
fires) - change configuration doesn't work
- add new item database (
controllerwillchangecontent
not fire) - switch working configuration
- the item added visible in
tableview
- switch non-working configuration
- the item visible in
tableview
- edit item (
controllerwillchangecontent
fired,controller:didchangeobject:
fired typensfetchedresultschangedelete
instead ofnsfetchedresultschangeupdate
) - change working configuration, , item changed , visible again.
i'm @ wits end thing. i'm out of ideas. there literally no difference between way these 2 fetchedresultscontrollers
created , 4 others. any can offered greatly appreciated.
--edit--
still having issues this. reiterate of answers techzen's questions:
- none of attributes set transient values
- i'm using flat model @ moment. it's single entity direct attributes. there no relationships.
- the problem persists caches set
nil
- i setting old
frc
's delegatenil
before every change, , setting newfrc
's delegateself
@ end of switch. consistant across 6frc
s - i releasing old
frc
, creating new 1 each time user switches different sort option.
for interested, code i'm using switch frc
in gist here
-- edit 2 --
starting bounty can point me in right direction on this.
-- edit 3 --
as requested, here code delegate methods:
-(void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller { [self.tableview beginupdates]; } -(void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id<nsfetchedresultssectioninfo>)sectioninfo atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type { switch (type) { case nsfetchedresultschangeinsert: [self.tableview insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangedelete: [self.tableview deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade]; break; } } -(void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath { switch (type) { case nsfetchedresultschangeinsert: [self.tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangedelete: [self.tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; break; case nsfetchedresultschangeupdate: if (!self.searchisactive) { [self configurecell:[self.tableview cellforrowatindexpath:indexpath] atindexpath:indexpath]; } else { [self.searchdisplaycontroller.searchresultstableview reloaddata]; } break; case nsfetchedresultschangemove: [self.tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; [self.tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade]; break; } } -(void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller { [self.tableview endupdates]; }
and info got data model:
// person.h #import <coredata/coredata.h> @interface person : nsmanagedobject { } @property (nonatomic, retain) nsstring * name; @property (nonatomic, retain) nsstring * company; @property (nonatomic, retain) nsstring * comments; @property (nonatomic, retain) nsstring * job; @property (nonatomic, retain) nsdate * logdate; @property (nonatomic, retain) nsstring * location; @property (nonatomic, retain) nsnumber * rating; @property (nonatomic, retain) nsstring * imagepath; @property (nonatomic, retain) nsstring * thumbpath; @end // person.m #import "person.h" @implementation person @dynamic name; @dynamic company; @dynamic comments; @dynamic job; @dynamic logdate; @dynamic location; @dynamic rating; @dynamic imagepath; @dynamic thumbpath; @end
info data model:
entity: person property: comments kind: attribute type: string optional: yes property: name kind: attribute type: string optional: no property: rating kind: attribute kind: int 16 optional: yes min value: 0 max value: 5 property: job kind: attribute kind: string optional: yes property: company kind: attribute kind: string optional: yes property: location kind: attribute kind: string optional: yes property: imagepath kind: attribute kind: string optional: yes property: thumbpath kind: attribute kind: string optional: yes property: logdate kind: attribute kind: date optional: yes
nothing special of this.
i reposting comment answer, requested.
both "job" , "location" attributes optional. new item add in 1 of broken configuration contain values these attributes? may item not added table because, owing attributes values , nsfetchedresultscontroller setup, not fetched @ all. same reasons, may that, once edited, item disappear table (because no longer belong table after editing).
edit:
to set initial value different nil, in core data person.m file add following method
- (void) awakefrominsert{ self.job = @""; self.location = @""; }
etc. way, initial values automatically inserted core data each time create new person object.
Comments
Post a Comment