CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ✓ |
| LangLanguage | Objective C++Objective C++ |
| License | MIT |
| ReleasedLast Release | Oct 2015 |
Maintained by Victor Pavlychko.
DynamicAssociatedProperties library automatically generates accessors for @dynamic properties defined in categories using objc_getAssociatedObject/objc_setAssociatedObject for backing storage.
Supported property attributes:
strong, copy and assign attributes implemented using runtime association policiesweak attribute implemented using value holder objectgetter and setter specifications are properly parsedNSValue or NSNumber
Supported types:
charunsigned charshortunsigned shortintunsigned intlongunsigned longlong longunsigned long longfloatdoubleBOOLCGPointCGVectorCGSizeCGRectCGAffineTransformUIEdgeInsetsUIOffsetCATransform3DTo add properties in a category simply declate them in your *.h file as usual
@interface AWTestClass (AWTestCategory)
@property (copy) NSString *awStringProperty;
@property (weak) id awWeakProperty;
@property (assign) NSInteger awIntegerProperty;
@property (assign) CGRect awCGRectProperty;
@endAnd define as @dynamic in your *.m file. Calling +[NSObject dynamicAssociatedPropertiesRegisterAll] will register all @dynamic properties for current class.
#include <DynamicAssociatedProperties/DynamicAssociatedProperties>
@implementation AWTestClass (AWTestCategory)
@dynamic awStringProperty;
@dynamic awWeakProperty;
@dynamic awIntegerProperty;
@dynamic awCGRectProperty;
+ (void)load
{
[self dynamicAssociatedPropertiesRegisterAll];
}
@endCustom value types can be easily registered but type safe solution will require Objective-C++ file here. Simply rename your implementation file to *.mm and follow this syntax:
#include <DynamicAssociatedProperties/AccessorBlockFactoryRegistry.h>
@implementation AWTestClass (AWTestCategory)
+ (void)load
{
AccessorBlockFactoryRegistry::instance().registerGetterAndSetterFactories<MyStructType>();
}
@endWhen adding missing SDK structs consider extending NSObject+DynamicAssociatedProperties.mm and submitting pull request ;)
DynamicAssociatedProperties is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "DynamicAssociatedProperties"To run the example project, clone the repo, and run pod install from the Example directory first.
Several alternative projects are available:
Victor Pavlychko, [email protected]
DynamicAssociatedProperties is available under the MIT license. See the LICENSE file for more info.