ios - Change a property on NSManagedObject, does it send a notification? -



ios - Change a property on NSManagedObject, does it send a notification? -

can alter property on nsmanagedobject in 1 location , notification somewhere else?

i need download bunch of photos , each photo's info server. in info model, retrieve photo's information, pass nsmanagedobject custom uiview display photo , photo's image. not set uiimageview's image yet cause don't have it.

my model begins retrieving each photo server asynchronously. when photo has completed downloading, want set nsmanagedobject property photo (just nsdata property). when that, want custom uiview notification object changed , set uiimaveview's image downloaded.

is possible custom uiview tell when nsmanagedobject has changed?

i inquire cause have noticed when add together catagory nsmanagedobject, when want set property, recommended like:

-(void)sethasnewdata:(nsnumber *)hasnewdata { [self willaccessvalueforkey:@"hasnewdata"]; [self setprimitivevalue:hasnewdata forkey:@"hasnewdata"]; [self didaccessvalueforkey:@"hasnewdata"]; self.modifieddatelocal = [nsdate date]; }

first, not recommend doing set accessor that. improve off using dynamic property , overriding lifecycle method -willsave , setting modified date there. way getting modified date of when saved disk , update modification date happens once per save. can like:

- (void)willsave { [super willsave]; if ([self changedvalues][@"modifieddatelocal"] == nil) return; [self setmodifieddatelocal:[nsdate date]]; }

when save happens, core info phone call -willsave on every entity before save occurs. if entity changes process started on again. hence check create sure didn't modify modifieddatelocal avoid infinite loop.

as uiview, can either utilize kvo (key value observing) watch property on specific instance of nsmanagedobject or can hear nsmanagedobjectcontextobjectsdidchangenotification fire time property on entity changes. warned though, chatty , hence expensive.

ios objective-c core-data nsmanagedobject

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -