Skip to content

Instantly share code, notes, and snippets.

@jdewind
Created June 16, 2011 14:09
Show Gist options
  • Save jdewind/1029290 to your computer and use it in GitHub Desktop.
Save jdewind/1029290 to your computer and use it in GitHub Desktop.
static void *kBindingContext = &kBindingContext;
@implementation MySlider
@synthesize requestModel;
@synthesize percent;
- (id)init {
if((self = [super init])) {
[requestModel addObserver:self forKeyPath:@"percentUploaded" options:0 context:kBindingContext];
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == kBindingContext) {
self.percent = self.requestModel.percentUploaded;
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)dealloc {
[requestModel removeObserver:self forKeyPath:@"percentUploaded"];
[requestModel release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment