Skip to content

Instantly share code, notes, and snippets.

@mattapperson
Last active August 29, 2015 14:07
Show Gist options
  • Save mattapperson/4ad43d75d2e1e83b9263 to your computer and use it in GitHub Desktop.
Save mattapperson/4ad43d75d2e1e83b9263 to your computer and use it in GitHub Desktop.
Get a Dictionary of native values to return to Titanium
// Where response is an instance of NativeCustomClass
NSDictionary *event = [self dictionaryValues:response fromClass:[NativeCustomClass class]];
- (NSDictionary*)dictionaryValues:(id) instance fromClass:(id) classType {
u_int count;
objc_property_t *properties = class_copyPropertyList(classType, &count);
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:count];
for (int i = 0; i<count; i++) {
NSString *str = [NSString stringWithCString:property_getName(properties[i])
encoding:NSUTF8StringEncoding];
//Set the dicationary values from our properties
[dict setValue:[instance valueForKey:str] forKey:str];
}
free(properties);
return [dict autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment