facebook/KVOController — pull request #40 by TongG (2014-11-15 19:55:40+00:00)
Title: Added a 'keyPath' parameter into "observe..." APIs

Hello there,

While I use the `observe:keyPaths: ... block:` API, I have to adopt the follow method to determine what should I do, it's very inconvenient:
```objective-c
self.KVOController = [ FBKVOController controllerWithObserver: self ];

[ self.KVOController observe: self.sliderLabel
keyPaths: @[ @"doubleValue", @"backgroundColor" ]
options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
block:
^( FBKAppDelegate* _Observer, NSTextField* _Object, NSDictionary* _Change )
{
id newChangeItem = _Change[ @"new" ];

/* I want to determine what should I do based on the keyPath:
* I expected to write like this: if ( [ keyPath isEqualToString: @"doubleValue" ] ) */
if ( [ newChangeItem isKindOfClass: [ NSNumber class ] ] )
; /* against the new value of key path "doubleValue" */

/* I want to determine what should I do based on the keyPath:
* I expected to write like this: if ( [ keyPath isEqualToString: @"backgroundColor" ] ) */
else if ( [ newChangeItem isKindOfClass: [ NSColor class ] ] )
; /* against the new value of key path "backgroundColor" */

/* BUT I can't!
* Because there is not a keyPath parameter in NSKeyValueObservingOptions's signature
*/
} ];
```

The same situation also appears in `observe:keyPaths: ... action:` API:
```objective-c
- ( void ) observedPropertiesChange: ( NSDictionary* )_Change object: ( id )_Object
{
id newChangeItem = _Change[ @"new" ];

/* I want to determine what should I do based on the keyPath:
* I expected to write like this: if ( [ keyPath isEqualToString: @"doubleValue" ] ) */
if ( [ newChangeItem isKindOfClass: [ NSNumber class ] ] )
; /* against the new value of key path "doubleValue" */

/* I want to determine what should I do based on the keyPath:
* I expected to write like this: if ( [ keyPath isEqualToString: @"backgroundColor" ] ) */
else if ( [ newChangeItem isKindOfClass: [ NSColor class ] ] )
; /* against the new value of key path "backgroundColor" */

/* BUT I can't!
* Because there is not a keyPath parameter in the documented action signature
*/
}
```

So I added a `keyPath` parameter into these API, now we can determine what should we do based on the `keyPath` parameter:

```objective-c
[ self.KVOController observe: self.sliderLabel
keyPaths: @[ @"doubleValue", @"backgroundColor" ]
options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
block:
^( NSString* _KeyPath, FBKAppDelegate* _Observer, NSTextField* _Object, NSDictionary* _Change )
{
id newChangeItem = _Change[ @"new" ];

/* Now we can Determine what should we do based on the keyPath */
if ( [ _KeyPath isEqualToString: @"doubleValue" ] )
; /* against the new value of key path "doubleValue" */

/* Ditto */
else if ( [ _KeyPath isEqualToString: @"backgroundColor" ] )
; /* against the new value of key path "backgroundColor" */
} ];
```

```objective-c
- ( void ) observedPropertiesChange: ( NSDictionary* )_Change
keyPath: ( NSString* )_KeyPath
object: ( id )_Object
{
id newChangeItem = _Change[ @"new" ];

if ( [ _KeyPath isEqualToString: @"doubleValue" ] )
; /* against the new value of key path "doubleValue" */

else if ( [ _KeyPath isEqualToString: @"backgroundColor" ] )
; /* against the new value of key path "backgroundColor" */
}
```

I also updated the documentation for these APIs.

For details, please see `Commits`.