i thought [moc existingobjectwithid:self.objectid error:&error] right way find existing object inside of thread, given objectid, can't work, why?
background / code
i've got nsmanagedobject saved. can see properties on main thread. i'm passing object nsoperation in custom init method , in method, i'm saving objectid:
- (instancetype)initwithentity:(nsmanagedobject *)object { self = [super init]; if (self) { self.objectid = object.objectid; ... } return self; } then in main function of operation i'm looking object can use it.
- (void)main { if (self.iscancelled) { return; } nsmanagedobjectcontext *moc = [nsmanagedobjectcontext mr_context]; nserror *error = nil; self.object = [moc existingobjectwithid:self.objectid error:&error]; if (error) { ddlogerror(@"error finding object: %@", error); } ... } mr_context magicalrecord method sets new context concurrency type nsprivatequeueconcurrencytype parent set root saving context. of looks correct me.
errors
when no debugger set, fault object. if try property on it, nil.
with debugger turned on , -com.apple.coredata.concurrencydebug 1 set errors:
in simulator exc_bad_instruction (code=exc_i386_invop, subcode=0x0) on [moc existingobjectwithid:self.objectid error:&error] line.
on device, following on same line:
coredata`+[nsmanagedobjectcontext __multithreading_violation_allthatislefttousishonor__]: -> 0x185946614 <+0>: brk #0x1 so wrong, objectid isn't temporary, same objectid see when inspecting real object on main thread. i'm not sure why isn't working.
i've tried:
self.object = [moc objectwithid:self.objectid]; but doesn't work either. ideas?
updates
2015-07-10 - ok, if use block moc can access object within block.
[moc performblock:^{ nserror *error = nil; nsmanagedobject *o = [moc existingobjectwithid:self.objectid error:&error]; }]; how extract object can have access in thread operation running? doing __block property , setting in block , using out of block failed.
is issue way context setup?
magicalrecord's context sets own queue perform operations on it. therefore, if want use up, have in block ([context performblock:] or [context performblockandwait:]) can perform on own queue , return nsoperation.
what ended doing creating couple __block properties , pulling needed contents object outside of block.
Comments
Post a Comment