Skip to content

Instantly share code, notes, and snippets.

@arturlector
Last active March 18, 2016 15:32
Show Gist options
  • Save arturlector/6df58c356bfca9655ffa to your computer and use it in GitHub Desktop.
Save arturlector/6df58c356bfca9655ffa to your computer and use it in GitHub Desktop.
Как добавить свойство в существующий объект с закрытой реализацией через runtime?

Как добавить свойство в существующий объект с закрытой реализацией через runtime?

Добавляем свойство в GMSPlace. Добавляем shortAddress через runtime.

#import <GoogleMaps/GoogleMaps.h>

@interface GMSPlace (Category)
@property (strong, nonatomic) NSString *shortAddress;

@end
#import "GMSPlace+Category.h"
#import <objc/runtime.h>

@implementation GMSPlace (Category)

- (NSString*) shortAddress {
    return objc_getAssociatedObject(self, @selector(shortAddress));
}

- (void)setShortAddress:(NSString *)shortAddress {
    objc_setAssociatedObject(self, @selector(shortAddress), shortAddress, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment