Last active
December 2, 2015 16:41
-
-
Save romainmenke/5bbfafecf7820d54426e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol SingletonDelegate : class { | |
func reportSingletonUpdate(value:Int) | |
} | |
class Singleton { | |
private static var privateShared : Singleton? | |
weak var delegate : SingletonDelegate? | |
class func shared() -> Singleton { | |
guard let uwShared = privateShared else { | |
privateShared = Singleton() | |
return privateShared! | |
} | |
return uwShared | |
} | |
class func destroy() { | |
privateShared = nil | |
} | |
func somethingHappened() { | |
guard let del = delegate else { | |
return | |
} | |
del.reportSingletonUpdate(0) | |
} | |
private init() { | |
} | |
} | |
class VC : UIViewController, SingletonDelegate { | |
override func viewDidAppear(animated: Bool) { | |
Singleton.shared().delegate = self | |
} | |
func reportSingletonUpdate(value: Int) { | |
print(value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment