Globally accessible helper class I would like to get opinion if I am doing this right. I am creating a helper class that is globally accessible to my whole project. I want it to be easily called like Facebook.loginUser()

My code is like this:

class Facebook: NSObject {
  class func LoginUser() {
    println("Login user...")
  }
} 


And on usage just call the class name and method:

Facebook.loginUser()


instead of:

var FB: Facebook = Facebook()
FB.loginUser()
This design pattern is known as a Singleton, and you can read more about them here.

It's super easy to set up a singleton in Swift, and when I use this pattern I forward all method calls to the shared instance of the class.

class Singleton {
    static let sharedInstance = Singleton()

    // type method (aka class method), allows for easy-access code
    class func doSomething() {
        // forward the method and any parameters to the shared instance
        sharedInstance.doSomething()
    }

    // instance method, visible through Singleton.sharedInstance
    func doSomething() {
        println("Did something.")
    }
}


And the usage would be like so:

Singleton.doSomething()
Singleton.sharedInstance.doSomething()


(Both call the same method, just the first one is more concise)

Notes:


Apple is calling class methods in swift type methods
I use camelCaseForMethodNames because it is a convention (instead of CapitalizingEveryWord like class names)
People tend to have mixed opinions about Singletons (read more about that here, if you desire).