Skip to content

Swift Singleton #64

Open
Open
@v5tech

Description

@v5tech

http://www.synappse.pl/swift-first-steps-singleton/

//
//  Singleton.swift
//  Test
//
//  Created by Sebastian Suchanowski on 6/5/14.
//  Copyright (c) 2014 Synappse. All rights reserved.
//

import Foundation

class Singleton {

    class func sharedInstance() -> Singleton! {
        struct Static {
            static var instance: Singleton? = nil
            static var onceToken: dispatch_once_t = 0
        }

        dispatch_once(&Static.onceToken) {
            Static.instance = self()
        }

        return Static.instance!
    }

    @required init() {

    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions