Implement a singleton class


I want to create a Singleton class.


// Creating our Singleton

class SharedManager {
    // Declare our 'sharedInstance' property
    static let sharedInstance = SomeManager()

    // Set an initializer - 
    // it will only be called once
    init() {
        print("SomeManager initialized")

    // Add a test function
    func doSth() {
        print("I'm doing something")

// The 'init' function will 
// only be called the first time



Find answers here

Hi there! Ask Us a Question We are ready to help