Why we should use struct and class function in singleton pattern?

Viewed 534

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()
}
2 Answers
Related