Kevin Sylvestre

Progress in Developing iOS and Cocoa

Over the past few iterations of iOS and Cocoa Apple has fundamentally changed the language and improved nearly every aspect. The removal of memory management (and replacement with ARC) has solved more than a few headaches. The addition of short form expressions and blocks means code can be refactored greatly. Here is a code snippet to show just how far the language has come:

Old:

//
//  SampleTableViewController.m
//  Sample
//
//  Created by Kevin Sylvestre on 13-07-11.
//  Copyright Kevin Sylvestre 2013. All rights reserved.
//

#import "SampleViewController.h"

@implementation SampleViewController

#pragma mark - Authentication

- (void)userSignupSuccess:(User *)user
{
  ...
}

- (void)userSignupFailure:(NSError *)error
{
  ...
}

- (void)signup
{
  NSArray *objects = [NSArray arrayWithObjects:@"Kevin", [NSNumber numberWithInt:24], [NSDate date]];
  NSArray *keys = @"name", @"age", @"modified";
  NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

  UserProcessor *up = [[UserProcessor alloc] init];

  up.delegate = self;
  [up create:params];

  [up release];
}

@end

New:

//
//  SampleTableViewController.m
//  Sample
//
//  Created by Kevin Sylvestre on 13-07-11.
//  Copyright Kevin Sylvestre 2013. All rights reserved.
//

#import "SampleViewController.h"

@implementation SampleViewController

#pragma mark - Authentication

- (void)signup
{
  [User create:@{ @"name" : @"Kevin", @"age" : @24 } 
    withSuccess:^(User *user) { ... } 
    andFailure:^(NSError *error) { ... }];
}

@end

This isn't the best of it though. An amazing new package manager has taken off that follows a similar format to the Ruby and Python equivalents. It is called CocoaPods and it rocks!