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
keypathon.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
Observeris 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
keypathThe keypath to observe.
objectThe object to observe
keypathon.optionsThe KVO options. The default value is
.Oldand.New.contextThe KVO context to observe in. The default value is nil.
completionThe block to perform when
keypathis set onobject. -
Registers
selfto observecenterfornamerestricted toobject.Declaration
Swift
public func beginObserving() -
Unregisters
selfto stop observingcenterfornamerestricted toobject.Declaration
Swift
public func endObserving()
View on GitHub
ObjectObserver Class Reference