Find answers here
Menu
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
SharedManager.sharedInstance.doSth()
SharedManager.sharedInstance.doSth()
Objective-C to Swift language converter | Visit iSwift Stories
WE CODE.