Created
November 17, 2008 00:37
-
-
Save cappuccino/25610 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); | |
} | |
+ (id)alloc | |
{ | |
var object = [CPDictionary alloc]; | |
object.isa = [self class]; | |
object._name = nil; | |
return object; | |
} | |
- (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]); | |
} | |
[invocation invoke]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment