Created
January 28, 2013 21:10
-
-
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
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
//# 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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