Preview:
//Here is signleton - that means you can create an object of a class outside it

class singleton{
  
  static let shared = singleton()
  init(){} //(Optional to do it or not)
  
  let temp = 5

}

//Usage

viewDidLoad(){
  let num = singleton.shared.temp
  
  //but also you can create object
  let obj = singleton()
  let num = obj.temp
}


//Here is Signleton - that means you cannot create an object of a class outside it

class Singleton{
  
  static let shared = singleton()
  private init(){} //(Optional to do it or not)
  
  let temp = 5

}

//Usage

viewDidLoad(){
  let num = singleton.shared.temp
  
  //but you cannot create object
  //let obj = singleton()
  //let num = obj.temp
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter