ObjectObserver
public final class ObjectObserver:NSObject, Observer
Implementation of Observer
for observing a keypath setter of an object. Observation begins on init
and ends on deinit
unless called otherwise.
For efficiency the class is marked as final. If necessary, convenience initialisers can be created using extensions.
-
The keypath being observed on
object
.Declaration
Swift
public let keypath:String
-
The object to to observe
keypath
on.Declaration
Swift
public let object:NSObject
-
The options applied to the observation.
Declaration
Swift
public let options:NSKeyValueObservingOptions
-
The context to observe in.
Declaration
Swift
public let context:UnsafeMutablePointer<Void>
-
Flag for whether this
Observer
is currently registered as an observer oncenter
.Declaration
Swift
public private(set) var observing:Bool = false
-
Default initialiser.
Declaration
Swift
public init(keypath:String, object:NSObject, options: NSKeyValueObservingOptions = [.Old, .New], context:UnsafeMutablePointer<Void> = nil, completion:(keypath:String, object:NSObject, change:[String:AnyObject]?) -> ())
Parameters
keypath
The keypath to observe.
object
The object to observe
keypath
on.options
The KVO options. The default value is
.Old
and.New
.context
The KVO context to observe in. The default value is nil.
completion
The block to perform when
keypath
is set onobject
. -
Registers
self
to observecenter
forname
restricted toobject
.Declaration
Swift
public func beginObserving()
-
Unregisters
self
to stop observingcenter
forname
restricted toobject
.Declaration
Swift
public func endObserving()