Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 0.38 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <objc/runtime.h>
  2.  
  3. @interface NSObject (AddProperty)
  4. @property (copy) NSString *string;
  5. @end
  6.  
  7. @implementation NSObject(AddProperty)
  8. - (NSString *)string
  9. {
  10.     id result = objc_getAssociatedObject(self, @"string");
  11.     return [[result copy] autorelease];
  12. }
  13. - (void)setString:(NSString *)string
  14. {
  15.     objc_setAssociatedObject(self, @"string", string, OBJC_ASSOCIATION_COPY);
  16. }
  17. @end