Last active
September 30, 2015 03:48
-
-
Save masakih/1716702 to your computer and use it in GitHub Desktop.
カテゴリでプロパティを追加する ref: http://qiita.com/items/386dd8e1a294c37085c6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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