开发者

Using -setValue:forKey: vs "object.var = ..."

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 as开发者_JS百科king 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜