Skip to content

Instantly share code, notes, and snippets.

@loganwright
Last active August 29, 2015 14:01
Show Gist options
  • Save loganwright/9ac0c39fe9f09d3efb5b to your computer and use it in GitHub Desktop.
Save loganwright/9ac0c39fe9f09d3efb5b to your computer and use it in GitHub Desktop.
Get All Attributes of A Property
#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