1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
class Singleton { static func get() { if( type._instance == null ) { type._instance = new type(); } return type._instance; } } /* Usage: class SoundManager is Singleton { func init() { } } var mgr = SoundManager.get(); //type is upvalue\preset value, like self */