Dynamic Accessors for Category Properties
##The Problem
Tired of the Runtime objc_getAssociatedObject
objc_setAssociatedObject
to the Category implementation method of @Dynamic Property?
Link Blog Post
##Installation
YSDynamicProperties
is available through CocoaPods, to install it simply add the following line to your Podfile:
pod 'YSDynamicProperties'
##Usage
- Add
#import "NSObject+YSDynamicProperties.h"
to Category file. - Define properties in
.h
Category file. - Add
@dynamic
statement for each property in.m
file.
Example:
@interface Superman (YSKit)
@property (strong, nonatomic) UIColor *ys_ShirtColor;
@property (strong, nonatomic) NSArray *ys_Weapons;
@end
#import "NSObject+YSDynamicProperties.h"
@implementation Superman (YSKit)
@dynamic ys_ShirtColor, ys_Weapons;
+ (void)load
{
[self implementDynamicPropertyAccessors];
}
@end
This code is distributed under the terms and conditions of the MIT license.
You can support me by:
- sending me iTunes Gift Cards;
- via Alipay: [email protected]
- via PayPal: [email protected]
:-)