Last active
August 29, 2015 14:07
-
-
Save mattapperson/4ad43d75d2e1e83b9263 to your computer and use it in GitHub Desktop.
Get a Dictionary of native values to return to Titanium
This file contains hidden or 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
// Where response is an instance of NativeCustomClass | |
NSDictionary *event = [self dictionaryValues:response fromClass:[NativeCustomClass class]]; |
This file contains hidden or 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
- (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