The difference between IOS agent and notification, KVC and KVO

Source: Internet
Author: User

Notice

Notification needs to have a notification center:nsnotificationcenter, custom notifications need to give a name, and then listen.

Pros:

Disadvantages: More Key-value observations (KVO) require more code, and the listener must be removed before it is erased.

Agreement

Using Setdelegate to set proxy objects, the most typical example is the common TableView.

Advantages: the classes that support it have detailed and specific information.

Disadvantages: the class must support delegates. There can be only one delegate connected to an object at a time.

Advantages of KVO:
 
When there is a property change, KVO will provide an automatic message notification. Developers do not need to implement such a scenario themselves: send a message notification each time the property changes.

This is the greatest advantage provided by the KVO mechanism. Since the scheme has been clearly defined, it can be easily adopted with framework-level support.

Developers do not need to add any code, they do not need to design their own observer model, directly can be used in the project.

Second, the KVO architecture is so powerful that it's easy to support multiple observers observing the same property, as well as related values.

The realization analysis of KVC

KVC used a isa-swizzling technique.

Isa-swizzling is the type-mixed pointer mechanism. KVC mainly through the isa-swizzling, to achieve its internal search and positioning.

The ISA pointer, which is the meaning of the is a kind of, points to the class that maintains the sub-published object. This sub-publication actually contains pointers and other data that point to the methods in the implementation class.

Http://www.isaced.com/post-201.html

http://blog.csdn.net/ajrm0925/article/details/7416419


This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1754492

The difference between IOS agent and notification, KVC and KVO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.