swift -- 单例

方式一: (类似OC)

class SingletonDispatch{

class var shareInstance : SingletonDispatch {

  //结构体

  struct Static {

       static var onceToken : dispatch_once_t = 0

     static var instance : SingletonDispatch? = nil

  }

  //创建

  dispatch_once(&Static.onceTokec){

    Static.instance = SingletonDispatch()

  }

  return Static.instance!

}

}

方式二:

class SingletonDispatch {

  class shareInstance : SingletonDispatch {

     struct Static {

    static var instance = SingletonDispatch()

  }

  return Static.instance

}

}

方式三:

class SingletonDispatch {

static let share Instance = SingletonDispatch()

private init() {}

}

//单例的创建

let single = SingletonDispatch.shareInstance

上一篇:tomcat 7/8 启动非常慢的解决方法


下一篇:部署war包后,新增tomcat服务器,启动tomcat服务器报错解决方法