Best improvement in Twitter 4.1 for iOS

The Februari 21 release post for the new Twitter version doesn’t mention my favorite improvement. Ever since the new UI was launched I had the feeling the app didn’t work very well together with app switching. Every single time I opened the app I was presented with a splash screen with a big logo, not a good sign in the age of iOS multitasking. The app was starting up fresh each time because the OS had shut it down, or worse: they presented this logo on purpose delaying me from seeing my timeline.

The 4.1 version solves this. The app is way more efficient now and I am presented with my timeline immediately. I have not seen a single restart of the app which was not caused by me forcing it to shut down on purpose. Also the new Launch image doesn’t contain a logo anymore:

This indicates to me Twitter realizes it’s in their and the users interest to launch as fast as possible.

My new favourite: Easy async NSURLConnection

Single line URL connections! I actually made my own category on NSURLConnection before, to do a similar thing. I’m happy this is now obsolete and I can use the iOS5/OSX10.7 built-in.

-[NSURLConnection sendAsynchronousRequest:queue:completionHandler];


    completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    // do something useful

Examples of sites using media queries

A big part of responsive web design is the use of media queries to enhance a page based on different viewing contexts. Most often this means changing the page styles/layout based on the page width. This makes it possible to optimize a website for different devices using only css. is a gallery of websites that take advantage of media queries in css. Click a demo and resize your window!

Launching the Twitter app to a profile, with web fallback

To give users of your iOS app the option to follow you on twitter, you could open the webpage of your app account. Better yet, why not just open the Twitter app itself? Most twitter users probably have the official client installed. Using the custom url scheme supported by the Twitter app, you can display your account profile directly. Users are now only one tap away from following you.

The following URL will open the app on the @app_devs profile page:

A reusable piece of code:

- (BOOL) openTwitterProfile:(NSString *)profileName {
    BOOL didOpenApp = NO;
    UIDevice *device = [UIDevice currentDevice];
    NSString *profileURLString = [NSString stringWithFormat:@"twitter://user?screen_name=%@", profileName];
    didOpenApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:profileURLString]];
    if (!didOpenOtherApp) {
        // fallback to Safari
        NSString *profileURLString = [NSString stringWithFormat:@"", profileName];
        didOpenApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:profileURLString]];
    return didOpenApp;

Singleton snipped for Xcode 4

The snippet configuration for a singleton class method mentioned in my previous post called sharedInstance.


+ (id) sharedInstance {
    static dispatch_once_t onceToken = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&onceToken, ^{
        _sharedObject = [[self alloc] init];
    return _sharedObject;


Singleton snippet for Xcode 4



Singletons in Objective-C

I recently switched to a new way of implementing singletons in Objective-C. Since most of my code now is iOS 4.0+ I started using GCD and blocks as recommended by Luke Redpath (ARC compatible):

+ (id) sharedInstance {
  static dispatch_once_t pred = 0;
  __strong static id _sharedObject = nil;
  dispatch_once(&pred, ^{
    _sharedObject = [[self alloc] init]; // or some other init method
  return _sharedObject;

Fully customizable activity indicator view

The idea of re-implementing standard UI components from iOS has been floating around in my head for a while now. The UI kit controls and views are great, but when working with designers you’ll notice they always tend to tweak everything a little. I’ll always advice you to use the standard controlls wherever possible, but wouldn’t it be great if you could customize the color or change the size a little bit?

I recently came across the Spin.js which implements a activity indicator using css and javascipt. This lead me to start working on my own customizable view for iOS, usable in native applications.

Introducing JKActivityIndicatorView

A custom implementation of a UIActivityIndicatorView. Everything will be customizable. Current customizable properties:

  • Number of lines
  • Line width
  • Line length
  • Animation speed
  • Radius

This is a work in progress, bug reports are welcome.

Source + demo app

A demonstration video (available in HD):

Please remember that an activity indicator view alone is usually not enough! Make sure you place it on a contrasting background if it’s not visible enough or when you don’t know what will be displayed underneath. How not to do this:

Can't Wait

Resize a UIImage the right way

When deadlines loom, even skilled and experienced programmers can get a little sloppy. The pressure to ship may cause them to cut corners and look for a quick and easy solution, even if that solution is sure to cause trouble later on. Eventually, their coding style devolves into copy and paste programming, a lamentable tactic that involves cherry-picking snippets of code from a past project and putting them to use in the current one.
Trevor’s Bike Shed

A great write-up on the risks of ‘copy-and-pase coding’. Solutions to coding problems found online might not always be the correct answer, they usually lack testing and might even contain hidden bugs. I’ve ran into posts like this on multiple occasions (both iOS and Android) where the most popular answer clearly was wrong. The problem is that not everyone will actually be able to see this and use the code as is in a project.

There’s a lot of wrong code floating around the net related to manipulating UIImage’s for example. Correct solutions for common UIImage manipulation tasks are discussed in the post Resize a UIImage the right way in the form of several UIImage categories.