Singleton with properties in Swift 3

For me this is the best way, make init private. Swift 3 \ 4 \ 5 syntax // MARK: – Singleton final class Singleton { // Can’t init is singleton private init() { } // MARK: Shared Instance static let shared = Singleton() // MARK: Local Variable var emptyStringArray = [String]() }

How to define Singleton in TypeScript

Since TS 2.0, we have the ability to define visibility modifiers on constructors, so now we can do singletons in TypeScript just like we are used to from other languages. Example given: class MyClass { private static _instance: MyClass; private constructor() { //… } public static get Instance() { // Do you need arguments? Make … Read more