Apr 18 2011

iPhone Unit Test tips: Read a file in your test

Category: bdd,objective-cgiordano scalzo @ 12:44 pm

Very often I need to unit test something read from a file, but it seems very difficult to accomplish this simple task in iOS, so usually I give up.
But today I felt was a good day to find a solution ;-)
In my code I want to read a JSon data from a file, so I wrote a simple test:

describe(@"Conference", ^{
    it(@"loads given a filename", ^{
        Conference *conference = [[Conference alloc]initWithFile:@"talks_with_three_tracks"];
        [[theValue([conference hasData]) should] beTrue];

with a simple init method:

-(id)initWithFile:(NSString *)filename{
    if ((self = [super init])) {
        NSString* path = [[NSBundle mainBundle] pathForResource:filename ofType:@"json"];
        NSError *error;
        NSString* talksString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
        talks = [talksString JSONValue];
    return self;

    return talks!=nil;

Unfortunately it doesn’t work :-( , because path is nil;
But here it isthe solution:
instead of using [NSBundle mainBundle], we should use the bundle associated with our class:

        NSString *path = [[NSBundle bundleForClass:[Conference class]] pathForResource:filename ofType:@"json"];

Simple and neat: thank you StackOverflow ;-)

Technorati Tags: , ,

Tags: , ,

Jul 09 2010

Simplified Ad Hoc Distribution in Xcode 3.2

Category: objective-cgiordano scalzo @ 11:41 am

Currently, Ad Hoc distribution is the only way to share an application to try itin to several devices or users (to maximum of 100 devices).
Despite the Apple’s reputation to create simple and effective things, the Ad Hoc Distribution is one of awkward and cumbersome process I’ve ever seen: I admit every time I need to change a certificate to add or remove certain devices or I’ve to check another application, I hold my breath and start cold sweat until the end of process… but, in Xcode 3.2 they simplified it a little bit.

In Build menu you can find a new entry, Build and Archive, that creates your application and archive it, allowing to share and signing it in a more confortable way:

All archived applications are in a new window of the Organizer:

When you “share” an application an ipa file is created and you can share it with your betatesters:

Just a little thing, but it’s useful to manage all versions.

More information can be found in this interesting post by Jeff LaMarche: if are serious about iPhone development you must subscribe his blog (and buy his book too ;-) )

Technorati Tags: , ,

Tags: , ,

Mar 17 2010

AgileCamp 2010: richness of difference

Category: agile,bdd,me,objective-c,presentationgiordano scalzo @ 2:59 pm

Some weeks ago, I has been lucky enough to attend to AgileCamp 2010, an awesome Barcamp organized by Sketchin, a Swiss UX and Web agency.
With my good fellows XpUg-gers Gabriele, Andrea and Indrit, we reached a lot of old and new friends, all of them caring about quality and “Things Got Right”.
I came back really enriched, mainly because I met people with experiences and point of view different than mine.

It has been my first Barcamp, so I though it was necessary to present something, and I decided to assemble a little introduction to Tdd coding for Iphone.

Here there is the video of my presentation:

AgileCamp – iPhone agile DEV (di Giordano Scalzo) from Sketchin on Vimeo.

Technorati Tags: , ,

Tags: , ,