Skip to content

Instantly share code, notes, and snippets.

@Vyazovoy
Created July 15, 2013 20:05
Show Gist options
  • Save Vyazovoy/6002974 to your computer and use it in GitHub Desktop.
Save Vyazovoy/6002974 to your computer and use it in GitHub Desktop.
Category with property.
#import <objc/runtime.h>
@interface UIView (MyClass)
@property (strong, nonatomic, readwrite, setter = my_setProperty:) NSObject *my_propery;
@end
static const char kProperty;
@implementation UIView (MyClass)
@dynamic my_property;
- (NSObject *)my_property {
return objc_getAssociatedObject(self, &kProperty);
}
- (void)sc_setProperty:(NSObject *)my_property {
objc_setAssociatedObject(self, &kProperty, my_property, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment