Easy use of IOS Watcher mode (KVO)

Source: Internet
Author: User

The full name of KVO is Key-value observing, which implements a mechanism for adding observers to the object of interest, which is notified when the value of the attribute changes, and we can handle the change accordingly. Students who have seen design patterns should know that this is a typical observer pattern. The biggest advantage of KVO is that the underlying framework has been supported, and developers do not need to implement a scheme to send notifications when property values change, thus greatly reducing the amount of development effort. Second, the KVO framework is powerful, enabling multiple observers to observe the same attribute, or an observer to listen for different properties.

The use of KVO is relatively simple, basically three steps:

1. Registered Observer

AddObserver:forKeyPath:options:context:

2. The Observer realizes

ObserveValueForKeyPath:ofObject:change:context:

3. Remove the viewer (when the view exits)

Removeobserver:forkeypath:

Easy use of IOS Watcher mode (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.