Latest 0.2
Homepage https://github.com/Inferis/IIAutoNSCoding
License MIT
Platforms ios 6, requires ARC
Authors

A contraption to make objects conform to NSSecureCoding without all the boilerplate code. Your objects become serializable and you don’t have to write a bucketload of tedious and hard to maintain encoding/decoding code.

This is not meant to generally replace NSCoding code in all your objects, but more for simple data model objects which are not too complex.

Adding this to your models makes them serialize all properties (where possible).

It changes the actual class at runtime to conform to NSSecureCoding.

It will not try to override existing implementations of NSCoding, and it will only modify classes of libraries in your app bundle.

Warning This is a bit of experimental.

Example

Suppose you have these models:

@interface SubModel : NSObject

@property (nonatomic, strong) NSNumber *aNumber;
@property (nonatomic, strong) NSValue *aValue;

@end

@interface TestModel : NSObject

@property (nonatomic, strong, readonly) NSString *suchReadOnly;
@property (nonatomic, strong) NSString *aString;
@property (nonatomic, strong) NSDate *aDate;
@property (nonatomic, strong, getter=getTheURL) NSURL *anURL;
@property (nonatomic, assign, setter=setTheBool:) BOOL aBool;
@property (nonatomic, assign) NSInteger anInteger;
@property (nonatomic, strong) SubModel *subModel;
@property (nonatomic, strong) NSArray *things;
@property (nonatomic, strong) NSDictionary *reference;

@end

As you can see, they don’t conform to NSCoding.

Adding II_AUTO_NSCODING() in their implementation:

@implementation TestModel

II_AUTO_NSCODING()

@end

@implementation SubModel

II_AUTO_NSCODING()

@end

makes sure they do. It automatically serializes all properties it can.

You can even have it do it recursively for every "non-compliant" class it encounters during encoding:

II_AUTO_NSCODING(AUTO_INJECT_CHILDREN)

But that’s even more experimental. 😉

Todo

  1. Write a slew of tests
  2. Turn this into a CocoaPod

No necessarily in that order.

License

This code is licensed under the MIT License.

Latest podspec

{
    "name": "IIAutoNSCoding",
    "platforms": {
        "ios": 6
    },
    "version": "0.2",
    "summary": "A way to add propertybased automatic NSCoding to any objects.",
    "homepage": "https://github.com/Inferis/IIAutoNSCoding",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "social_media_url": "https://twitter.com/inferis",
    "authors": {
        "Tom Adriaenssen": "http://inferis.org/"
    },
    "source": {
        "git": "https://github.com/Inferis/IIAutoNSCoding.git",
        "tag": "0.2"
    },
    "source_files": "IIAutoNSCoding/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This