Joris Kluivers

I like to build software.

Singleton Snippet for Xcode 4

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

Code

1
2
3
4
5
6
7
8
+ (id) sharedInstance {
    static dispatch_once_t onceToken = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&onceToken, ^{
        _sharedObject = [[self alloc] init];
    });
    return _sharedObject;
}

Configuration

Singleton snippet

Usage

1
singleton<tab>