In Swift, a single case differs from OC in that it is written in many different ways, and if a. Swift file creates only one class, you can use that dispatch_once notation, If there are many classes in a. Swift file, an error will be made, and it needs to be written as below, so that the page is more simple
Declaring static properties at the bottom
1 static var resourcebundle:nsbundle?
Implemented in a function
1 //MARK:-------Weibo resource bundle--------2 classFunc bundle ()NSBundle3 {4 ifSelf.resourcebundle = =Nil {5Self.resourcebundle = NSBundle (Path:NSBundle.mainBundle (). Pathforresource ("Resourceweibo", OfType:"Bundle")!)!6 }7 returnself.resourcebundle!8}
This makes it very simple to implement a single example, even if the class is created repeatedly, and Singleton properties are only generated once
How to do a single example in Swift