Skip to content

Instantly share code, notes, and snippets.

@minikin
Last active March 20, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minikin/1efa3ac791dcc1e5c2e5 to your computer and use it in GitHub Desktop.
Save minikin/1efa3ac791dcc1e5c2e5 to your computer and use it in GitHub Desktop.
Singleton in Swift
// Singleton in Swift
import Foundation
class Animal: NSObject {
static let sharedAnimal = Animal()
}
let cat = Animal.sharedAnimal
let dog = Animal.sharedAnimal
if cat === dog {
print("The two objects are identical")
} else {
print("The two objects are not identical")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment