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