Skip to content

Instantly share code, notes, and snippets.

@demonnico
Last active December 21, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demonnico/6340768 to your computer and use it in GitHub Desktop.
Save demonnico/6340768 to your computer and use it in GitHub Desktop.
nice helper to code.
#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