FBKVOController Class Reference

Inherits from NSObject
Declared in FBKVOController.h

Overview

FBKVOController adds support for handling key-value changes with blocks and custom actions, as well as the NSKeyValueObserving callback. Notification will never message a deallocated observer. Observer removal never throws exceptions, and observers are removed implicitely on controller deallocation. FBKVOController is also thread safe. When used in a concurrent environment, it protects observers from possible ressurection and avoids ensuing crash. By default, the controller maintains a strong reference to objects observed.

+ controllerWithObserver:

Creates and returns an initialized KVO controller instance.

+ (instancetype)controllerWithObserver:(id)observer

Parameters

observer

The object notified on key-value change.

Return Value

The initialized KVO controller instance.

Declared In

FBKVOController.h

– initWithObserver:retainObserved:

The designated initializer.

- (instancetype)initWithObserver:(id)observer retainObserved:(BOOL)retainObserved

Parameters

observer

The object notified on key-value change. The specified observer must support weak references.

retainObserved

Flag indicating whether observed objects should be retained.

Return Value

The initialized KVO controller instance.

Discussion

Use retainObserved = NO when a strong reference between controller and observee would create a retain loop. When not retaining observees, special care must be taken to remove observation info prior to observee dealloc.

Declared In

FBKVOController.h

– initWithObserver:

Convenience initializer.

- (instancetype)initWithObserver:(id)observer

Parameters

observer

The object notified on key-value change. The specified observer must support weak references.

Return Value

The initialized KVO controller instance.

Discussion

By default, KVO controller retains objects observed.

Declared In

FBKVOController.h

  observer

The observer notified on key-value change. Specified on initialization.

@property (atomic, weak, readonly) id observer

Declared In

FBKVOController.h

– observe:keyPath:options:block:

Registers observer for key-value change notification.

- (void)observe:(id)object keyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options block:(FBKVONotificationBlock)block

Parameters

object

The object to observe.

keyPath

The key path to observe.

options

The NSKeyValueObservingOptions to use for observation.

block

The block to execute on notification.

Discussion

On key-value change, the specified block is called. Inorder to avoid retain loops, the block must avoid referencing the KVO controller or an owner thereof. Observing an already observed object key path or nil results in no operation.

Declared In

FBKVOController.h

– observe:keyPath:options:action:

Registers observer for key-value change notification.

- (void)observe:(id)object keyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options action:(SEL)action

Parameters

object

The object to observe.

keyPath

The key path to observe.

options

The NSKeyValueObservingOptions to use for observation.

action

The observer selector called on key-value change.

Discussion

On key-value change, the observer’s action selector is called. The selector provided should take the form of -propertyDidChange, -propertyDidChange: or -propertyDidChange:object:, where optional parameters delivered will be KVO change dictionary and object observed. Observing nil or observing an already observed object’s key path results in no operation.

Declared In

FBKVOController.h

– observe:keyPath:options:context:

Registers observer for key-value change notification.

- (void)observe:(id)object keyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context

Parameters

object

The object to observe.

keyPath

The key path to observe.

options

The NSKeyValueObservingOptions to use for observation.

context

The context specified.

Discussion

On key-value change, the observer’s -observeValueForKeyPath:ofObject:change:context: method is called. Observing an already observed object key path or nil results in no operation.

Declared In

FBKVOController.h

– observe:keyPaths:options:block:

Registers observer for key-value change notification.

- (void)observe:(id)object keyPaths:(NSArray *)keyPaths options:(NSKeyValueObservingOptions)options block:(FBKVONotificationBlock)block

Parameters

object

The object to observe.

keyPaths

The key paths to observe.

options

The NSKeyValueObservingOptions to use for observation.

block

The block to execute on notification.

Discussion

On key-value change, the specified block is called. Inorder to avoid retain loops, the block must avoid referencing the KVO controller or an owner thereof. Observing an already observed object key path or nil results in no operation.

Declared In

FBKVOController.h

– observe:keyPaths:options:action:

Registers observer for key-value change notification.

- (void)observe:(id)object keyPaths:(NSArray *)keyPaths options:(NSKeyValueObservingOptions)options action:(SEL)action

Parameters

object

The object to observe.

keyPaths

The key paths to observe.

options

The NSKeyValueObservingOptions to use for observation.

action

The observer selector called on key-value change.

Discussion

On key-value change, the observer’s action selector is called. The selector provided should take the form of -propertyDidChange, -propertyDidChange: or -propertyDidChange:object:, where optional parameters delivered will be KVO change dictionary and object observed. Observing nil or observing an already observed object’s key path results in no operation.

Declared In

FBKVOController.h

– observe:keyPaths:options:context:

Registers observer for key-value change notification.

- (void)observe:(id)object keyPaths:(NSArray *)keyPaths options:(NSKeyValueObservingOptions)options context:(void *)context

Parameters

object

The object to observe.

keyPaths

The key paths to observe.

options

The NSKeyValueObservingOptions to use for observation.

context

The context specified.

Discussion

On key-value change, the observer’s -observeValueForKeyPath:ofObject:change:context: method is called. Observing an already observed object key path or nil results in no operation.

Declared In

FBKVOController.h

– unobserve:keyPath:

Unobserve object key path.

- (void)unobserve:(id)object keyPath:(NSString *)keyPath

Parameters

object

The object to unobserve.

keyPath

The key path to observe.

Discussion

If not observing object key path, or unobserving nil, this method results in no operation.

Declared In

FBKVOController.h

– unobserve:

Unobserve all object key paths.

- (void)unobserve:(id)object

Parameters

object

The object to unobserve.

Discussion

If not observing object, or unobserving nil, this method results in no operation.

Declared In

FBKVOController.h

– unobserveAll

Unobserve all objects.

- (void)unobserveAll

Discussion

If not observing any objects, this method results in no operation.

Declared In

FBKVOController.h