swift 创建单例模式

class func sharedInstance()-> GlobalConstant {

        struct YRSingleton{

            static var predicate:dispatch_once_t = 0

            static var instance:GlobalConstant? = nil

        }

        dispatch_once(&YRSingleton.predicate,{

            YRSingleton.instance = GlobalConstant()

            }

        )

        return YRSingleton.instance!

    }

posted @ 2015-03-27 11:10  shidaying  阅读(148)  评论(0编辑  收藏  举报