Help us understand the problem. What is going on with this article?

addObserver:forKeyPath:options:context: リファレンスを調べた

More than 3 years have passed since last update.



Registers anObserver to receive KVO notifications for the specified key-path relative to the receiver.

func addObserver(_ observer: NSObject,
      forKeyPath keyPath: String,
         options options: NSKeyValueObservingOptions,
         context context: UnsafeMutablePointer<Void>)



The object to register for KVO notifications. The observer must implement the key-value observing method observeValueForKeyPath:ofObject:change:context:.

KVO通知にオブザーザとして登録されるオブジェクト。このオブジェクトはKVOメソッドの observeValueForKeyPath:ofObject:change:context: を実装してなければならない。


The key path, relative to the receiver, of the property to observe. This value must not be nil.

監視するプロパティの key path です。必須です。
(key path はプロパティ名を文字列で指定する)


A combination of the NSKeyValueObservingOptions values that specifies what is included in observation notifications. For possible values, see NSKeyValueObservingOptions.

監視したい通知を含んだ NSKeyValueObservingOptions の組合せです。 NSKeyValueObservingOptions を指定します。


Arbitrary data that is passed to anObserver in observeValueForKeyPath:ofObject:change:context:.

observeValueForKeyPath:ofObject:change:context: に送られる仲裁データです。


Neither the receiver, nor anObserver, are retained. An object that calls this method must also call either the removeObserver:forKeyPath: or removeObserver:forKeyPath:context: method when participating in KVO.

レシーバもオブザーバも保持(retain)されません。KVOを利用してこのメソッドを呼び出すオブジェクトは removeObserver:forKeyPath: または removeObserver:forKeyPath:context: も呼び出す必要が有ります。

Emacs 好きなプログラマー、 (iOS|Web) 開発。 好きなプログラマー格言は「楽をする為ならどんな苦労も厭わない」 Qiitaは自分用のメモとして使ってます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away