Last active
December 11, 2015 20:39
-
-
Save vgrichina/4657230 to your computer and use it in GitHub Desktop.
My extension of https://github.com/th-in-gs/THObserversAndBinders project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CXBinder.h | |
// TheList | |
// | |
// Created by Vladimir Grichina on 28.01.13. | |
// Copyright (c) 2013 TheList, LLC. All rights reserved. | |
// | |
#import <THObserversAndBinders/THBinder.h> | |
@interface CXBinder : THBinder | |
@end | |
#define BIND(fromObj, fromPath, toObj, toPath) [CXBinder binderFromObject:fromObj keyPath:fromPath toObject:toObj keyPath:toPath] | |
#define BIND_T(fromObj, fromPath, toObj, toPath, transform) [CXBinder binderFromObject:fromObj keyPath:fromPath toObject:toObj keyPath:toPath transformationBlock:^id(id value) { return transform; }] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CXBinder.m | |
// TheList | |
// | |
// Created by Vladimir Grichina on 28.01.13. | |
// Copyright (c) 2013 TheList, LLC. All rights reserved. | |
// | |
#import "CXBinder.h" | |
@interface THBinder(private) | |
- (id)initForBindingFromObject:(id)fromObject keyPath:(NSString *)fromKeyPath | |
toObject:(id)toObject keyPath:(NSString *)toKeyPath | |
transformationBlock:(THBinderTransformationBlock)transformationBlock; | |
@end | |
@implementation CXBinder | |
- (id)initForBindingFromObject:(id)fromObject keyPath:(NSString *)fromKeyPath | |
toObject:(id)toObject keyPath:(NSString *)toKeyPath | |
transformationBlock:(THBinderTransformationBlock)transformationBlock | |
{ | |
if (self = [super initForBindingFromObject:fromObject keyPath:fromKeyPath | |
toObject:toObject keyPath:toKeyPath | |
transformationBlock:transformationBlock]) { | |
if (transformationBlock) { | |
[toObject setValue:transformationBlock([fromObject valueForKeyPath:fromKeyPath]) | |
forKeyPath:toKeyPath]; | |
} else { | |
[toObject setValue:[fromObject valueForKeyPath:fromKeyPath] | |
forKeyPath:toKeyPath]; | |
} | |
} | |
return self; | |
} | |
- (void)dealloc | |
{ | |
[self stopBinding]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment