0

I learn the Swift Language and i need to create a manager like a Parse sdk.

For exemple when you initialize your Parse in app you write

Parse.setApplication("...", applicationId:"...")

And later you can write code like this

Parse.doSomething()

The method doSomething() use initial context.

Can you show me in my class should look like? I try some singleton exemple, but a have MyClass.sharedAttribute.doSomething() in case

Nikunj
  • 655
  • 3
  • 13
  • 25
bourvill
  • 152
  • 1
  • 13
  • Possible duplicate of [dispatch\_once singleton model in swift](http://stackoverflow.com/questions/24024549/dispatch-once-singleton-model-in-swift) – 0x416e746f6e Dec 24 '15 at 14:01

1 Answers1

4

What you have shown is no indication of singletons whatsoever, it sounds and looks more like a static class with static members and properties:

class MyStatic {
    static var appIdA : String?

    class func setApplicationId(a : String) {
        appIdA = a
    }

    class func doSomething() {
        print(appIdA)
    }
}


MyStatic.setApplicationId("blabla")

MyStatic.doSomething() // prints Optional("blabla")

Of course there is the possibility that internally the class is a singleton, but Parse does not seem to be one, just looking at the functions it exposes.

The code comments even state

/*!
 The `Parse` class contains static functions that handle global configuration 
 for the Parse framework.
 */
luk2302
  • 55,258
  • 23
  • 97
  • 137