Skip to content

Instantly share code, notes, and snippets.

@soulfly
Last active August 29, 2015 14:02
Show Gist options
  • Save soulfly/ba799017ec7e1922b730 to your computer and use it in GitHub Desktop.
Save soulfly/ba799017ec7e1922b730 to your computer and use it in GitHub Desktop.
Swift singleton implementation
var myInstance:ChatService?
class ChatService {
class func instance() -> ChatService{
if !myInstance {
myInstance = ChatService()
println("init")
}
return myInstance!
}
}
...
var a = ChatService.instance()
var b = ChatService.instance()
println(a===b)
@HoldFast88
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment