// // NGAConditionalExecutor.m // P4Menu // // Created by Michael Bishop on 9/29/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "NGAConditionalExecutor.h" #import "NGAUtilities.h" @interface NGAConditionalExecutor () -(NSDictionary*)currentDictionaryWithValues; @end @implementation NGAConditionalExecutor +(id)executorWithConditionalKeyPaths:(NSArray*)keypaths object:(id)object { return AUTORELEASE([[NGAConditionalExecutor alloc] initWithConditionalKeyPaths:keypaths object:object]); } -(id)init { return [self initWithConditionalKeyPaths:nil object:nil]; } - (id)initWithConditionalKeyPaths:(NSArray*)keypaths object:(id)object { if ((self = [super init]) == nil) return nil; _keypaths = [keypaths copy]; _object = object; _values = [[self currentDictionaryWithValues] copy]; return self; } #if !__has_feature(objc_arc) -(void)dealloc { [_values release]; [_keypaths release]; [super dealloc]; } #endif -(NSDictionary*)currentDictionaryWithValues { return [_object dictionaryWithValuesForKeys:_keypaths]; } -(BOOL)conditionallyExecuteBlock:(void(^)())block { if ( ![_values isEqualToDictionary:[self currentDictionaryWithValues]] ) return NO; block(); return YES; } @end