RestKit: Post and Return Results

Posted on Tuesday, July 24th, 2012 under iOS, Rails

I’ve spent the last couple of weeks getting to know RestKit. We’re using it for some new internal projects including building the new Spots iOS App on it.

Something that I found interesting and with little documentation online is how to POST an object to a server over JSON but also to easily retain the results that are sent back. Here’s how:

Overview

In this example we’re going to be working with a User object which has two characteristics.

  • ID
  • Device ID

Nothing crazy, all nice and simple. We’re going to check if the Device ID already exists within the users table. If not, we’ll create it whilst retaining the newly created ID.

User Object

User.h

#import Foundation/Foundation.h

@interface User : NSObject

@property (nonatomic, retain) NSNumber* identifier;
@property (nonatomic, retain) NSString *device_id;

@end

User.m

#import "User.h"

@implementation User

@synthesize device_id, identifier;

@end

Posting and Returning

I’ve already created an NSDictionary which contains all live User IDs and Device IDs call userList. I then check against the userList dictionary to see if the Device Id exists. If it doesn’t, create it and assign the newly created ID to currentUser.identifier:

if ([[usersList allKeys] containsObject:device_id) {
    NSLog(@"User exists");

    currentUser.identifier = [usersList objectForKey: device_id];
    currentUser.device_id = device_id;
} else {
    NSLog(@"Nope, never seen it");

    RKObjectRouter *router = [RKObjectManager sharedManager].router;
    [router routeClass:[User class] toResourcePath:@"/users.json" forMethod:RKRequestMethodPOST];

    RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
    [userMapping mapKeyPath:@"device_id" toAttribute:@"device_id"];
    [userMapping mapKeyPath:@"id" toAttribute:@"identifier"];

    [[RKObjectManager sharedManager].mappingProvider registerMapping:userMapping withRootKeyPath:@"user"];
    currentUser.device_id = device_id;

    [[RKObjectManager sharedManager] postObject:currentUser usingBlock:^(RKObjectLoader *loader){
        loader.onDidLoadObject = ^(id obj) {
            NSLog(@"UserID: %@", currentUser.identifier);
        };
    }];
}

Shipping spots.io in one week

Posted on Wednesday, March 21st, 2012 under Apps

You can view spots.io here.

I’ve always had the ambition to ship a product in one week. After reading up and getting tonnes of advice on shipping products, the best advice I’ve received thus far is “Ship early and ship often”.

You can always reiterate on the product and make all of the gorgeous tweaks you wanted to down the line. Your main goal should be to get something built and live as early as possible.

Doesn’t this equate to bad work?

No. Far to often we plan an idea open up photoshop and spend to much time tweaking how a gradient or border looks. You should be focusing on getting the fundamentals of the product built. The meat.

Once you have the foundations of the product created, you can start to show the world something. The longer you spend in photoshop or tweaking details before you go live, the longer people have to wait.

All products are not good products. We think up of ideas very quickly now. It’s easy to build a web application. The Internet is vast knowledge base to help get you started which means there are tonnes of web apps being built on a daily basis. Only a few are adopted.

You can start to see very quickly what the adoption rate of your product is the sooner you have a fundamentally fully working product to show people. Ship early and ship often.

Continue Reading…

What is Curation?

Posted on Tuesday, March 20th, 2012 under Apps, Design

With more and more information becoming available, curation is becoming a bigger part of our lives. Services like Percolate help us weed out the none important information by allowing our social friends to become curators for us.

Statistical Simplicity

Posted on Tuesday, February 21st, 2012 under Apps, Statistics

Statistics should be used to improve your product. They provide insight into how it’s performing and intuitive feedback on what your users love and hate. It’s not always easy to plan for every iteration when you’re developing the product. How the user interface functions, where are your users getting lost, will the user’s actually use this as I intend them to?

It’s very easy to see how invaluable statistics can be. Yet some products can cloud your decisions with too much metrics in a clutter fashion. Say hello to Gaug.es

Continue Reading…

We dropped the ball on TechEvents.ie

Posted on Sunday, February 12th, 2012 under Apps

TechEvents.ie was created about 2 years ago now. It started from humble beginings of just me posting the latest technical events in Ireland, weekly. The site slowly grew traction and as it did I could step back and allow others to post their events. Leaving me to get back to what I love, writing code.

Continue Reading…

Getting social with iOS and Twitter

Posted on Monday, January 9th, 2012 under iOS, kickit

The next step for kickit was some social abilities. It would be a great addition to the app if the user could post to their friends on twitter about their progress. Kicking the habit is hard enough. The addition of help from friends and family would be a great benefit.

The Learning Curve

I had never added twitter posting abilities to an iOS application before. This was all going to be new to me, all over again. I started by digging through some of Apple’s extensive developer documentation. I discovered that built in to the SDK is a wonderful little twitter package. Perfect.

There are draw backs to using the integrated twitter method in iOS5. Mainly, it’s not backwards compatible. Anyone using pre iOS5 would get an alert asking them to update before they could update their kick ass followers on twitter. This didn’t deter me. Onwards and upwards.

Continue Reading…

kickit 1.3 Release Notes

Posted on Sunday, January 8th, 2012 under iOS, kickit

Here’s a list of bug fixes and feature improvements coming in the next release of kickit for iPhone and iPod touch. We’re hoping to have them in the app store by the end of January.

If you notice any bug that is not described below, feel free to pop us an email

Continue Reading…

kickit gets some healthy updates

Posted on Tuesday, December 20th, 2011 under Apps, iOS

Since the launch of kickit, I’ve received some great feedback. Financially incentivizing someone to kick the habit is a great motivational method. The other main reason to kick the habit is your health restoration. The longer you remain free from smoking, the greater you body’s health improves.

Continue Reading…

A comprehensive list of design tools

Posted on Monday, December 5th, 2011 under Apps, Design, iOS, Mac

Design is a creative endeavor than can run smoother with the right tools. I’ve put together a list of some of the tools I love to use when designing. Hopefully they’ll bring you as much joy as they’ve given me when I stumbled upon them:

Continue Reading…

Learning the road of iOS development

Posted on Wednesday, November 23rd, 2011 under Design, iOS, Learning

It’s been an ambition of mine to create an iOS application. I’ve watched other iOS developers create really awesome apps and wanted to get a piece of the action. Mainly from a learning standpoint. The goal of the first app being, creating an application that’s well designed and simplistic. I’ve never developed an iOS app before, everything was new to me. Where to start?

Continue Reading…