Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 01-03-2012, 12:02 AM   #12 (permalink)
newDev
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 73
newDev is on a distinguished road
Default

This is an example of how I make singletons:

Code:
static RouteData *sharedData;

+(RouteData*)sharedData{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!sharedData) sharedData = [[RouteData alloc]init];
    });
    return sharedData;
}
The dispatch once token and block ensure that the singleton is only allocated once.
__________________
Sir Charles Barkley
newDev is offline   Reply With Quote
 

» Advertisements
» Online Users: 430
11 members and 419 guests
apatsufas, aqlucky, DavisWenins, Hamood, iLearnColors, iOS.Lover, jaychoupham, MAMN84, QuantumDoja, tadaki, Viekiehug
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,613
Threads: 94,086
Posts: 402,792
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tadaki
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.