Created
August 13, 2014 13:32
-
-
Save naoty/0aff43e98f866ac9bdad to your computer and use it in GitHub Desktop.
推奨されてるシングルトンパターンの実装、structのネストの位置を変えても動いた
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
| import UIKit | |
| class Manager { | |
| struct Singleton { | |
| static let instance = Manager() | |
| } | |
| class var sharedInstance: Manager { | |
| println("sharedInstance called") | |
| // struct Singleton { | |
| // static let instance = Manager() | |
| // } | |
| return Singleton.instance | |
| } | |
| let name: String | |
| init(name: String = "sample user") { | |
| self.name = name | |
| } | |
| } | |
| let instanceA = Manager.sharedInstance | |
| let instanceB = Manager.sharedInstance | |
| if instanceA === instanceB { | |
| println("singleton pattern") | |
| } else { | |
| println("not singleton pattern") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment