[Off-Topic] iOS Development and Open Source Libraries

2011 March 26, 15:59 h

I’ve been following the evolution of iOS development and I have to say that is becoming increasingly easier to assemble a quality application these days. Apple just released iOS 4.3.1 and Xcode 4.0.1. Great releases, and the new Xcode is a great step forward. I think this is the first big IDE to fully support Git as a first class citizen in the development workflow. Every serious IDE should do it and any serious developer should be comfortable with Git by now.

The new LLVM Compiler 2.0 is very impressive, it helps a lot in making memory leak free applications. By the way, I don’t buy the “it is too difficult doing memory management”, this is just saying “I’m too lazy and cheap”. Come on, there are thousands of quality apps both for OS X and iOS. Memory management is a little bit more difficult than having a full features generational garbage collector, but it’s nowhere near as difficult as some people claim it to be. Any reasonable developer should be able to accomplish this with minimum effort.

And to help even more, the community has been releasing more and more great libraries that further increase productivity. Let me list a few of my favorites:

1
2
3
4
5
6
#import "FlurryAPI.h"
...
- (void) applicationDidFinishLaunching:(NSNotification*) notice {
  [FlurryAPI startSession:@"your_unique_app_key"];
  ...
}

And there are several other methods for you to count certain events in your app, to log page views, to log exceptions and errors, and even location. Definitely mandatory for every app.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- (IBAction)grabURLInTheBackground:(id)sender
{
   if (![self queue]) {
      [self setQueue:[[[NSOperationQueue alloc] init] autorelease]];
   }
 
   NSURL *url = [NSURL URLWithString:@"https://allseeing-i.com"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request setDidFinishSelector:@selector(requestDone:)];
   [request setDidFailSelector:@selector(requestWentWrong:)];
   [[self queue] addOperation:request]; //queue is an NSOperationQueue
}
 
- (void)requestDone:(ASIHTTPRequest *)request
{
   NSString *response = [request responseString];
}
 
- (void)requestWentWrong:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}

This library creates network queues and you can trigger as many connection requests as you want and it will manage the queue for you in the background. There are use case example in the documentation. With this library there is no need to use the low level base classes and you should delegate all HTTP requests to this library. Highly recommended.

1
2
3
4
5
6
- (void)requestDone:(ASIHTTPRequest *)request
{
   NSString *response = [request responseString];
   NSError *theError = NULL;
   NSDictionary *theDictionary = [NSDictionary dictionaryWithJSONString:response error:&theError];
}

Super easy. It supports deserializing a JSON string into a graph of Objective-C objects and it also supports the way back to convert objects into a JSON representation so you can POST it somewhere or just record it into a local file.

1
2
3
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
 target:self
 action:@selector(share)]

And adding the event handler code:

1
2
3
4
5
6
7
8
9
10
11
12
- (void)myButtonHandlerAction
{
        // Create the item to share (in this example, a url)
        NSURL *url = [NSURL URLWithString:@"https://getsharekit.com"];
        SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];

        // Get the ShareKit action sheet
        SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

        // Display the action sheet
        [actionSheet showFromToolbar:navigationController.toolbar];
}

Can’t get easier than that.

1
2
3
4
5
6
7
8
9
10
11
12
13
describe(@"Team", ^{
    context(@"when newly created", ^{
        it(@"should have a name", ^{
            id team = [Team team];
            [[team.name should] equal:@"Black Hawks"];
        });
        
        it(@"should have 11 players", ^{
            id team = [Team team];
            [[[team should] have:11] players];
        });
    });
});

Both are definitely worth checking out. And we should strive to add more technology and techniques for testing in Objective-C development. We did in the Ruby-land, there’s no reason we can’t do the same in Objective-C.

And this is it for now. There are many more great libraries and tools available and iOS is evolving fast, so this is all very exciting to follow and practice. I hope to be able to contribute back as soon as possible.

tags: learning beginner apple objective-c english

Comments

comentários deste blog disponibilizados por Disqus