// // NGAAutoObserver.h // P4Menu // // Created by Michael Bishop on 10/3/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import <Foundation/Foundation.h> // Use this to observe one's own properties in clearer code than the standard KVO methods. // All you need to do is: // 1 - register/deregister in your init/dealloc methods // 2 - Create a special method named valueDidChangeFor<KeyPath> and it will be called // when that property has changed. // If you add a colon to the end of your specially named method, you will get // the change dictionary of the change (with new/old values) // You can also specify key paths in your valueDidChangeFor<KeyPath> like // valueDidChangeForKey_key_key_key: /* CHANGE ------ -(id)init { ... [self addObserver:self forKeyPath:@"info" options:0 context:NULL]; [self addObserver:self forKeyPath:@"client.name" options:0 context:NULL]; ... } -(void)dealloc { ... [self removeObserver:self forKeyPath:@"info"]; [self removeObserver:self forKeyPath:@"client.name"]; ... } -(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context { if ( [keyPath isEqualToString:@"info"] ) DO_SOMETHING_WITH_INFO_CHANGE if ( [keyPath isEqualToString:@"client.name"] ) DO_SOMETHING_WITH_CLIENT_CHANGE } TO -- #import "NGAAutoObserver.h" -(id)init { ... [self registerAllAutoObservationMethods]; ... } -(void)dealloc { ... [self unregisterAllAutoObservationMethods]; ... } -(void)valueDidChangeForInfo:(NSDictionary*)change { DO_SOMETHING_WITH_INFO_CHANGE } -(void)valueDidChangeForClient_name:(NSDictionary*)change { DO_SOMETHING_WITH_CLIENT_CHANGE } */ @interface NSObject (NGAAutoObservation) -(void)registerObserverMethodsForKeyPaths:(NSArray*)keyPaths; -(void)deregisterObserverMethodsForKeyPaths:(NSArray*)keyPaths; -(void)registerAllAutoObservationMethods; -(void)unregisterAllAutoObservationMethods; @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 20722 | jdputsch | initial branch, prep for -Zapp= support | ||
//guest/michael_bishop/MacMenu/src/NGAUtilities/Source/NGAAutoObserver.h | |||||
#1 | 8331 | Matt Attaway |
Adding initial version of MacMenu for Perforce MacMenu is a helpful Perforce client that sits in your toolbar. It allows you to run standard Perforce operations on the document that is open the currently active editor/viewer. |