ios - Accessing a core data NSManagedObject after resuming from background crashes the app -
i'm using core data , have found app crashing after resuming background. i've identified crash occurring inside block method body when try access property on nsmanagedobject
subclass.
i have property holds reference nsmanagedobject
subclass.
@property(nonatomic,strong) calitem *calobject;
to reproduce crash first need call child viewcontroller(noteviewcontroller
) passing block (notetextblock
).
noteviewcontroller *noteviewcontroller = [[noteviewcontroller alloc]initwithnote:self.calobject.note notetextblock:^(nsstring *notetext) { self.calobject.note = notetext; //crashing here }];
then send app background , resume it. afterwards in noteviewcontroller i'll return message calling viewcontroller.
if (self.notetextblock) { self.notetextblock(trimmedstring); }
when block returns , line self.calobject.note = notetext
gets executed app crashes.
so apparently can't put block on stack, quite , resume app , continue defined inside block ? or doing wrong here ?
edit:
*** terminating app due uncaught exception 'nsobjectinaccessibleexception', reason: 'coredata not fulfill fault '0xb253100 <x-coredata://c2304b7c-7d51-4453-9993-d33b9113a7a5/dtoday/p57>''
the block defined inside child viewcontroller:
@property(nonatomic, copy)notetextblock notetextblock;
edit2
when set breakpoint on line crashes.
(lldb) po self.calobject
$2 = 0x0b4464d0 <dtoday: 0xb4464d0> (entity: dtoday; id: 0xb489d00 <x-coredata://c2304b7c-7d51-4453-9993-d33b9113a7a5/dtoday/p57> ; data: <fault>)
i'm using magicalrecord lib manage core data stuff.
- (void)applicationdidbecomeactive:(uiapplication *)application { if ([nsmanagedobjectcontext mr_defaultcontext] == nil || [nsmanagedobjectmodel mr_defaultmanagedobjectmodel] == nil || [nspersistentstorecoordinator mr_defaultstorecoordinator] == nil || [nspersistentstore mr_defaultpersistentstore] == nil ) { //coming background, re-init coredata stack [magicalrecordhelpers setupcoredatastackwithautomigratingsqlitestorenamed:dbname]; }
i not familiar magicalrecords, ...
this exception raised when have un-faulted (as can seen in edit2) object no longer (or never had) exists in store.
might happen in few cases:
- another context has deleted store
- you have inserted it, obtained permanent id and:
** refreshed it
** saved (but parent context), reseted parent, , refreshed object in current context (or imported fault main context), seeobjectwithid:
there might other cases i'm forgetting, or unaware of.
if describe stack structure, , object state/origin might able understand problem better
Comments
Post a Comment