Try the search, it's linked to some great forums

Saturday, December 8, 2012

Creating a Singleton

Let's say you want a view that persists, such that you can see where you are in a data table or sumthin.  Good place for a singleton.  This can be done by creating a custom GETTER for that object, like this;
// Customer GETTER for creating a singleton of this object
WhatsOverThereViewController* whatsOverThereViewController = nil;
- (WhatsOverThereViewController*) whatsOverThereViewController {

    if(whatsOverThereViewController != nil)
    {
        NSLog(@"We already have one of these things, I'm NOT creating another one");
        return whatsOverThereViewController;
    }
    WhatsOverThereViewController *whatsOverThereViewController = [[WhatsOverThereViewController alloc] init];
    NSLog(@"ALLOC / INIT the WhatsOverThereVC");
    return whatsOverThereViewController;
}
Or something like this

reference tutorials/templates;
Provides code for cut & paste -  http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/