قالب وردپرس درنا توس
Home / IOS Development / ios – Singletons in Swift 5

ios – Singletons in Swift 5



Here is exactly how I make a singleton,

  public class Model
{
static let split = model ()
// For ocd friends. Add this line: private init () {}

func test () -> Double
{
return 3.33
}
}

then somewhere else …

  class ViewController: UIViewController
{
override func viewDidLoad ()
{
super.viewDidLoad ()
print ("Holy singleton test, Batman!  (Model.shared.test ())")
}
}

How about in Swift 5?

Any new dramas or insights? Did they perhaps add "actual" singletons, or?


Source link