views:

109

answers:

1

The difference between these two lines of code is that the second is KVO compliant and the first isn't?

[person setValue:tempPerson.name forKey:@"name"];
person.name = tempPerson.name;

The reason I'm asking is because I need to update 60 attributes on over 500 objects, I don't want KVO notifications for more than a handful of attributes.

I'm using NSFecthedResultsController for my UITableView and I don't want to trigger excessive setNeedDisplay on the cells.

+3  A: 

There is no difference between the two lines as far as Key-Value Observing is concerned. Both trigger KVO notifications by default. You can override this behavior, though. From Apples' KVO Programming Guide:

You can control automatic observer notifications for properties of your subclass by implementing the class method automaticallyNotifiesObserversForKey:. Subclasses can test the key passed as the parameter and return YES if automatic notification should be enabled, NO if it should be disabled.

Ole Begemann
Thanks, so it's just a different style and no benefit to using either approach?
Andrew
The first line executes slower and is harder to read, so I see no benefit in using it unless you have to (that is, the name of the property is a variable and not known at compile time).
Ole Begemann
gotcha, thanks again
Andrew