1.1 --- a/BLIP/BLIPDispatcher.m Sat May 24 17:25:06 2008 -0700
1.2 +++ b/BLIP/BLIPDispatcher.m Tue Jul 21 15:06:15 2009 -0700
1.3 @@ -39,11 +39,13 @@
1.4 @synthesize parent=_parent;
1.5
1.6
1.7 +#if ! TARGET_OS_IPHONE
1.8 - (void) addTarget: (MYTarget*)target forPredicate: (NSPredicate*)predicate
1.9 {
1.10 [_targets addObject: target];
1.11 [_predicates addObject: predicate];
1.12 }
1.13 +#endif
1.14
1.15
1.16 - (void) removeTarget: (MYTarget*)target
1.17 @@ -58,12 +60,29 @@
1.18
1.19 - (void) addTarget: (MYTarget*)target forValueOfProperty: (NSString*)value forKey: (NSString*)key
1.20 {
1.21 +#if TARGET_OS_IPHONE
1.22 + Assert(target);
1.23 + [_predicates addObject: $array(key,value)];
1.24 + [_targets addObject: target];
1.25 +#else
1.26 [self addTarget: target
1.27 forPredicate: [NSComparisonPredicate predicateWithLeftExpression: [NSExpression expressionForKeyPath: key]
1.28 rightExpression: [NSExpression expressionForConstantValue: value]
1.29 modifier: NSDirectPredicateModifier
1.30 type: NSEqualToPredicateOperatorType
1.31 options: 0]];
1.32 +#endif
1.33 +}
1.34 +
1.35 +
1.36 +static BOOL testPredicate( id predicate, NSDictionary *properties ) {
1.37 +#if TARGET_OS_IPHONE
1.38 + NSString *key = [predicate objectAtIndex: 0];
1.39 + NSString *value = [predicate objectAtIndex: 1];
1.40 + return $equal( [properties objectForKey: key], value );
1.41 +#else
1.42 + return [(NSPredicate*)predicate evaluateWithObject: properties];
1.43 +#endif
1.44 }
1.45
1.46
1.47 @@ -72,8 +91,8 @@
1.48 NSDictionary *properties = message.properties.allProperties;
1.49 NSUInteger n = _predicates.count;
1.50 for( NSUInteger i=0; i<n; i++ ) {
1.51 - NSPredicate *p = [_predicates objectAtIndex: i];
1.52 - if( [p evaluateWithObject: properties] ) {
1.53 + id p = [_predicates objectAtIndex: i];
1.54 + if( testPredicate(p, properties) ) {
1.55 MYTarget *target = [_targets objectAtIndex: i];
1.56 LogTo(BLIP,@"Dispatcher matched %@ -- calling %@",p,target);
1.57 [target invokeWithSender: message];