Re: will/didChangeValueForKey: Real World Usage
Re: will/didChangeValueForKey: Real World Usage
- Subject: Re: will/didChangeValueForKey: Real World Usage
- From: Ben Trumbull <email@hidden>
- Date: Tue, 23 Oct 2007 14:41:51 -0700
Thanks, I.S. I had considered something like that, but now we're
adding ^even more^ code! Let me repeat that, as is, the code in my
original post works perfectly. If I had not heard lectures from
Apple on this topic, I wouldn't even be worried. If I remember
correctly, the exact admonition was against sending will/did change
as consecutive statements. At least I executed some code in between,
which ^usually^ changes the value. Am I going to add alot of code to
fix something that's not broken?
A number of good suggestions were made. But to answer your literal
question, no, it's not a problem removing from an empty set. Of
course, some of the observers might do a little more work than they
otherwise needed to, but this is not illegal.
I'm reminded of a similar situation in Core Data. For a to-many
relationship, NSManagedObject gives me a mutable set and, If I'm not
mistaken, I can insert/remove/replace its contents as I please. Here
is an accessor, which was generated by mogenerator:
- (NSMutableSet*)gluesSet {
return [self mutableSetValueForKey:@"glues"];
}
Look, it doesn't even send a willAccessValueForKey/
didAccessValueForKey, yet I can insert/remove/change the contents of
this set (not replacing whole thing, as you recommended), and Core
Data observes whatever I did and it all "just works".
-glueSet isn't implementing a property, it's forwarding a message.
-mutableSetValueForKey is a part of Key Value Coding.
NSManagedObject is fully KVC/KVO compliant for all its modeled
properties, so here KVC is doing all the work to honor Core Data's
design requirements like -willAccessValueForKey.
You can poke at it in gdb if you want to see the control flow.
Is this magic built into Core Data only?
No, magic is just illusion by another name.
--
terminally curious,
-Ben
__________________________________________________________________________
Ben Trumbull
email@hidden Development Technologies
(408) 974-5790 Core Data
Change is the Epitome of Hope. Apple, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden