swift单例

###普通版单例

class TheOneAndOnlyKraken {

static let sharedInstance = TheOneAndOnlyKraken()

//This prevents others from using the default '()' initializer for this class.

private init() {}     

}        

###多线程版单例

 class func theOneAndOnlyKraken() -> TheOneAndOnlyKraken{
    struct Singleton {
        static var predicate:dispatch_once_t = 0
        static var instance:TheOneAndOnlyKraken? = nil
    }
    dispatch_once(&Singleton.predicate, {
        Singleton.instance = TheOneAndOnlyKraken()
    })
    return Singleton.instance!
}