Skip to content

Instantly share code, notes, and snippets.

@brunogama
Created January 28, 2013 21:10
Show Gist options
  • Save brunogama/4659036 to your computer and use it in GitHub Desktop.
Save brunogama/4659036 to your computer and use it in GitHub Desktop.
http://www.g8production.com/post/41358908279/how-to-get-the-class-of-a-property-with-objective-c HOW TO GET THE CLASS OF A PROPERTY WITH OBJECTIVE-C RUNTIME REFERENCE
//# How to get the Class of a Property of a Objective-C Class with Objective-C Runtime Reference.
+ (id)getPropertyClass:(objc_property_t)currentProperty
{
NSString *currentPropertyAttrs = [NSString stringWithUTF8String:property_getAttributes(currentProperty)];
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"T@\"[a-zA-Z0-9]+\"" options:NSRegularExpressionCaseInsensitive error:&error];
if(error == nil)
{
NSRange rangeOfFirstMatch = [regex rangeOfFirstMatchInString:currentPropertyAttrs options:0 range:NSMakeRange(0, [currentPropertyAttrs length])];
if(rangeOfFirstMatch.length > 0)
{
NSString *propertyClassName = [currentPropertyAttrs substringWithRange:NSMakeRange(3, rangeOfFirstMatch.length-1-3)];
id propertyClass = NSClassFromString(propertyClassName);
return propertyClass;
}
}
return nil;
}
@brunogama
Copy link
Author

Source from the post: HOW TO GET THE CLASS OF A PROPERTY WITH OBJECTIVE-C RUNTIME REFERENCE

http://www.g8production.com/post/41358908279/how-to-get-the-class-of-a-property-with-objective-c

by Daniele Galiotto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment