The key path, relative to object
, to the value that has changed.
observeValue(forKeyPath:of:change:context:)
Availability
- iOS 2.0+
- iPadOS 2.0+
- macOS 10.3+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Technology
- Foundation ファウンデーション
Declaration 宣言
func observeValue(forKeyPath keyPath: String
?,
of object: Any?,
change: [NSKeyValueChangeKey
: Any]?,
context: UnsafeMutableRawPointer
?)
Parameters パラメータ
keyPath
object
The source object of the key path
key
.Path change
A dictionary that describes the changes that have been made to the value of the property at the key path
key
relative toPath object
. Entries are described inChange Dictionary Keys
.context
The value that was provided when the observer was registered to receive key-value observation notifications.
Discussion 解説
For an object
to begin sending change notification messages for the value at key
, you send it an add
message, naming the observing object that should receive the messages. When you are done observing, and in particular before the observing object is deallocated, you send the observed object a remove
or remove
message to unregister the observer, and stop sending change notification messages.