Skip to content

Instantly share code, notes, and snippets.

@woolsweater
Created July 11, 2013 19:49
Show Gist options
  • Save woolsweater/5978625 to your computer and use it in GitHub Desktop.
Save woolsweater/5978625 to your computer and use it in GitHub Desktop.
Getting metadata for property in category.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Rigby : NSObject
@end
@implementation Rigby
@end
@interface Rigby (Eleanor)
@property (nonatomic, copy) NSString * jarByTheDoor;
@property (nonatomic, copy) NSString * riceInTheChurch;
@end
@implementation Rigby (Eleanor)
@dynamic jarByTheDoor;
- (NSString *)riceInTheChurch
{
return @"";
}
- (void)setRiceInTheChurch:(NSString *)riceInTheChurch
{
return;
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
objc_property_t jar = class_getProperty([Rigby class], "jarByTheDoor");
NSLog(@"%s", property_getAttributes(jar));
objc_property_t rice = class_getProperty([Rigby class], "riceInTheChurch");
NSLog(@"%s", property_getAttributes(rice));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment