Last active
December 21, 2015 17:29
-
-
Save demonnico/6340768 to your computer and use it in GitHub Desktop.
nice helper to code.
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
#import <objc/runtime.h> | |
//iPhone4's wallpaper size in iOS7 | |
#define kWallpaperSizeNomal CGSizeMake(370.0,598.0) | |
//iPhone5's wallpaper size in iOS7 | |
#define kWallpaperSizeSpec CGSizeMake(372.0,696.0) | |
//esay to get the string value of patameter's name. | |
#define NameStringOfParam(param) [NSString stringWithFormat:@"%s", #param] | |
//add accessor(setter getter) for category by define. | |
#define SYNTHESIZE_CATEGORY_OBJ_PROPERTY(propertyGetter, propertySetter) \ | |
- (id) propertyGetter { \ | |
return objc_getAssociatedObject(self, @selector( propertyGetter )); \ | |
} \ | |
- (void) propertySetter (id)obj{ \ | |
objc_setAssociatedObject(self, @selector( propertyGetter ), obj, OBJC_ASSOCIATION_RETAIN_NONATOMIC); \ | |
} | |
#define SYNTHESIZE_CATEGORY_VALUE_PROPERTY(valueType, propertyGetter, propertySetter) \ | |
- (valueType) propertyGetter { \ | |
valueType ret = {0}; \ | |
[objc_getAssociatedObject(self, @selector( propertyGetter )) getValue:&ret]; \ | |
return ret; \ | |
} \ | |
- (void) propertySetter (valueType)value{ \ | |
NSValue *valueObj = [NSValue valueWithBytes:&value objCType:@encode(valueType)]; \ | |
objc_setAssociatedObject(self, @selector( propertyGetter ), valueObj, OBJC_ASSOCIATION_RETAIN_NONATOMIC); \ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment