Latest 1.0.1
Homepage https://github.com/mergesort/NSObject-Builder
License MIT
Platforms ios 4.0, requires ARC
Frameworks Foundation
Authors

NSObject-Builder

Use the builder pattern with a category on NSObject

Before, our a call to sign up a user could look a little like this:

User *user = [[User alloc] init];
user.username = @"joe"
NSString *password = @"supersecret"
user.email = @"[email protected]"

[User signUpUser:user password:password completion:^(User *user, NSError *error) {
    //some completion handling
}];

But now we have something cleaner, like this:

User const *user = [User buildObject:^User *(User *builder) {
    builder.username = @"joe"
    builder.email = @"[email protected]"
}];
NSString *password = @"supersecret"

[User signUpUser:user password:password completion:^(User *user, NSError *error) {
    //some completion handling
}];

The main benefit is that the object is immutable as well, which is great since all we want to do is pass it up to the server. A side benefit is that all the code is self-contained, so I know that I won’t find bits of setting the user object scattered elsewhere.

Do what you want with this code, I love you all.

Latest podspec

{
    "name": "NSObject+Builder",
    "version": "1.0.1",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "homepage": "https://github.com/mergesort/NSObject-Builder",
    "authors": {
        "Joe Fabisevich": "[email protected]"
    },
    "summary": "A category on NSObject for implementing the builder pattern on any object.",
    "source": {
        "git": "https://github.com/mergesort/NSObject-Builder.git",
        "tag": "1.0.1"
    },
    "source_files": "*.{h,m}",
    "frameworks": "Foundation",
    "requires_arc": true,
    "social_media_url": "https://twitter.com/mergesort",
    "platforms": {
        "ios": "4.0"
    }
}

Pin It on Pinterest

Share This