Last active
August 29, 2015 14:01
-
-
Save loganwright/9ac0c39fe9f09d3efb5b to your computer and use it in GitHub Desktop.
Get All Attributes of A Property
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
#import <objc/runtime.h> | |
- (NSArray *) attributesForProperty:(objc_property_t)property { | |
// Get attributes as char | |
const char * attributes = property_getAttributes(property); | |
// Make NSString | |
NSString * attributeString = [NSString stringWithUTF8String:attributes]; | |
// Array of Attributes | |
NSArray * attributesArray = [attributeString componentsSeparatedByString:@","]; | |
/* | |
For example, if you wanted to see if a property is read only, you could search for this attribute | |
if ([attributesArray containsObject:@"R"]) { | |
// is ReadOnly | |
} | |
*** Full List and Explanation *** | |
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW5 | |
*** End *** | |
*/ | |
return attributesArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment