I'm just reading a code from Udacity learning stuff. The teacher makes an instance variable sharedInstance
with a struct
that wrapped in a class function
Why can we not simply make a static var
?
class BugFactory() {
class func sharedInstance() -> BugFactory {
struct Singleton {
static var sharedInstance = BugFactory()
}
return Singleton.sharedInstance
}
}
Why It's not recommended:
class BugFactory() {
static var sharedInstance = BugFactory()
}