Skip to content

Instantly share code, notes, and snippets.

@masakih
Last active September 30, 2015 03:48
Show Gist options
  • Select an option

  • Save masakih/1716702 to your computer and use it in GitHub Desktop.

Select an option

Save masakih/1716702 to your computer and use it in GitHub Desktop.
カテゴリでプロパティを追加する ref: http://qiita.com/items/386dd8e1a294c37085c6
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment