Skip to content

Instantly share code, notes, and snippets.

@cappuccino
Created November 17, 2008 00:37
Show Gist options
  • Save cappuccino/25610 to your computer and use it in GitHub Desktop.
Save cappuccino/25610 to your computer and use it in GitHub Desktop.
@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