Created
April 13, 2017 07:19
-
-
Save dreampiggy/2f2da443874b329a2f5d12f546a7a0cf to your computer and use it in GitHub Desktop.
Objective-C Category Property Macro
This file contains 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
#ifndef TTD_CATEGORY_PROPERTY | |
#define TTD_CATEGORY_PROPERTY | |
#import <objc/runtime.h> | |
#define TTD_GET_PROPERTY(property) objc_getAssociatedObject(self, @selector(property)); | |
#define TTD_SET_STRONG(property) objc_setAssociatedObject(self, @selector(property), property, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
#define TTD_SET_COPY(property) objc_setAssociatedObject(self, @selector(property), property, OBJC_ASSOCIATION_COPY_NONATOMIC); | |
#define TTD_SET_UNSAFE_UNRETAINED(property) objc_setAssociatedObject(self, @selector(property), property, OBJC_ASSOCIATION_ASSIGN); | |
#define TTD_SET_ASSIGN(property, value) objc_setAssociatedObject(self, @selector(property), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
#define TTD_SET_WEAK(property) id __weak __weak_object = property; \ | |
id (^__weak_block)() = ^{ return __weak_object; }; \ | |
objc_setAssociatedObject(self, @selector(property), __weak_block, OBJC_ASSOCIATION_COPY); | |
#define TTD_GET_WEAK(property) objc_getAssociatedObject(self, @selector(property)) ? ((id (^)())objc_getAssociatedObject(self, @selector(property)))() : nil; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment