Created
November 16, 2008 22:39
-
-
Save nickjs/25581 to your computer and use it in GitHub Desktop.
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
@implementation LEProfilePresentation : CPDictionary | |
{ | |
CPString _name @accessors(property=name); | |
} | |
- (void)mapToView:(CPView)aView | |
{ | |
for(var i = 0; i < [[self allKeys] count]; i++) | |
{ | |
var key = [self allKeys][i]; | |
if([aView respondsToSelector:key]) | |
{ | |
[aView setValue:[self objectForKey:key] forKey:key]; | |
[self addObserver:self forKeyPath:key options:CPKeyValueObservingOptionNew context:aView]; | |
} | |
} | |
} | |
- (void)observeValueForKeyPath:(CPString)key ofObject:(id)object change:(CPDictionary)change context:(id)aView | |
{ | |
console.log(key) | |
if(aView) | |
if([aView respondsToSelector:key]) | |
[aView setValue:[self objectForKey:key] forKey:key]; | |
} | |
- (CPMethodSignature)methodSignatureForSelector:(SEL)selector | |
{ | |
return 1; | |
} | |
- (void)forwardInvocation:(CPInvocation)invocation | |
{ | |
var sel = [invocation selector]; | |
if([sel hasSuffix:":"]) | |
sel = [sel substringToIndex:[sel length]-1]; | |
if([sel hasPrefix:"set"]) | |
{ | |
sel = [sel substringFromIndex:3]; | |
var x = [sel substringToIndex:1]; | |
x = [x lowercaseString]; | |
sel = x + [sel substringFromIndex:1]; | |
[invocation setTarget:self]; | |
[invocation setSelector:@selector(setValue:forKey:)]; | |
[invocation setArgument:[invocation argumentAtIndex:2] atIndex:2]; | |
[invocation setArgument:sel atIndex:3] | |
} | |
else | |
{ | |
[invocation setTarget:self]; | |
[invocation setSelector:@selector(valueForKey:)]; | |
[invocation setArgument:sel atIndex:2]; | |
console.log([self valueForKey:sel]); | |
} | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment