KVUtils.h
author Jens Alfke <jens@mooseyard.com>
Mon Apr 14 13:58:48 2008 -0700 (2008-04-14)
changeset 4 64823cdde6a5
parent 0 d84d25d6cdbb
permissions -rw-r--r--
Minor improvements.
     1 //
     2 //  KVUtils.h
     3 //  MYUtilities
     4 //
     5 //  Created by Jens Alfke on 2/25/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import <Cocoa/Cocoa.h>
    10 
    11 
    12 enum {
    13     MYKeyValueObservingOptionOnce = 1<<31,
    14     MYKeyValueObservingOptionDelayed = 1<<30
    15 };
    16 
    17 
    18 
    19 @interface Observance : NSObject
    20 {
    21     id _target;
    22     id _observed;
    23     NSString *_keyPath;
    24     NSKeyValueObservingOptions _options;
    25     SEL _action;
    26 }
    27 
    28 - (id) initWithTarget: (id)target 
    29                action: (SEL)action
    30              observed: (id)observed
    31               keyPath: (NSString*)keyPath 
    32               options: (NSKeyValueObservingOptions)options;
    33 
    34 - (void) stopObserving;
    35 
    36 @property (readonly) id observed;
    37 @property (readonly) NSString* keyPath;
    38 
    39 @end
    40 
    41 
    42 
    43 @interface Observer : NSObject
    44 {
    45     id _target;
    46     NSMutableArray *_observances;
    47 }
    48 
    49 - (id) initWithTarget: (id)target;
    50 
    51 @property (readonly) id target;
    52 
    53 - (void) observe: (id)observed 
    54          keyPath: (NSString*)keyPath 
    55          options: (NSKeyValueObservingOptions)options
    56           action: (SEL)action;
    57 
    58 - (void) observe: (id)observed 
    59          keyPath: (NSString*)keyPath 
    60           action: (SEL)action;
    61 
    62 /** observed or keyPath may be nil, meaning wildcard */
    63 - (void) stopObserving: (id)observedOrNil keyPath: (NSString*)keyPathOrNil;
    64 - (void) stopObserving: (id)observed;
    65 - (void) stopObserving;
    66 
    67 @end