Latest 0.0.3
Homepage https://github.com/mysterioustrousers/MYSCategoryProperties
License MIT
Platforms ios 5.0, osx 10.6, requires ARC
Dependencies MYSRuntime
Frameworks Foundation
Authors

Quickly add properties to categories using runtime associations. Property names must follow the 3 letter prefix (e.g. mys_property) category naming convention in order for this to work.

Installation

In your Podfile, add this line:

pod "MYSCategoryProperties"

Instructions

Add properties to your header file:

@interface NSString (Example) 
@property (nonatomic, copy  ) NSDate    *mys_typedAt;
@property (nonatomic, assign) NSInteger mys_firstSpaceIndex;
@end

Import the header:

#import <MYSCategoryProperties.h>

Add @dynamic for each property in your implementation file:

@implementation NSString (Example)
@dynamic mys_typedAt;
@dynamic mys_firstSpaceIndex;
...

Call this method in + (void)load (which is called on each category of a class):

+ (void)load
{
    [MYSCategoryProperties setup:self];
}

And that’s it!

You can now use the properties like normal:

NSString *string = @"A string";
string.mys_typedAt = [NSDate date];
string.mys_firstSpaceIndex = 1;

NSLog(@"A string: "%@" that was typed at %@ has a space at %d", string, string.mys_typedAt, string.mys_firstSpaceIndex);

Contributing

Please update and run the tests before submitting a pull request. Thanks.

Credit

Much inspiration and code taken from https://github.com/gangverk/GVUserDefaults

Author

Adam Kirk (@atomkirk)

Latest podspec

{
    "name": "MYSCategoryProperties",
    "version": "0.0.3",
    "summary": "Quickly add properties to categories using runtime associations.",
    "description": "                   Quickly add properties to categories using runtime associations.n                   * Only implements getters and setters for dynamic properties.n                   * Only implements setters for properties not marked as `readonly`.n                   * Names getters and setters automatically unless the property declaration specifies customer getter/setter names.n                   * It is **highly** recommended that you prefix your category methods with a 3 letter prefix (e.g. 'mys').n",
    "homepage": "https://github.com/mysterioustrousers/MYSCategoryProperties",
    "license": "MIT",
    "authors": {
        "Adam Kirk": "[email protected]"
    },
    "platforms": {
        "ios": "5.0",
        "osx": "10.6"
    },
    "source": {
        "git": "https://github.com/mysterioustrousers/MYSCategoryProperties.git",
        "tag": "0.0.3"
    },
    "source_files": "MYSCategoryProperties/MYSCategoryProperties.{h,m}",
    "frameworks": "Foundation",
    "requires_arc": true,
    "dependencies": {
        "MYSRuntime": [
            "~> 0.0.2"
        ]
    }
}

Pin It on Pinterest

Share This