#include <objc/runtime.h>
@interface NSObject (AddProperty)
@property (copy) NSString *string;
@end
@implementation NSObject(AddProperty)
- (NSString *)string
{
id result = objc_getAssociatedObject(self, @"string");
return [[result copy] autorelease];
}
- (void)setString:(NSString *)string
{
objc_setAssociatedObject(self, @"string", string, OBJC_ASSOCIATION_COPY);
}
@end
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
16