title: Singleton and init with parameter
body: <p>I want to use the singleton pattern in my class which has a private <code>init</code> with parameter. It also has a class function called <code>setup</code> which configures and creates the shared instance. My objective-c code would be: </p>
  
  <pre><code>@interface MySingleton: NSObject
  
  + (MySingleton *)setup:(MyConfig *)config;
  + (MySingleton *)shared;
  @property (readonly, strong, nonatomic) MyConfig *config;
  
  @end
  
  
  @implementation MySingleton
  
  static MySingleton *sharedInstance = nil;
  
  + (MySingleton *)setup:(MyConfig *)config {
      static dispatch_once_t onceToken;
      dispatch_once(&amp;onceToken, ^{
          sharedInstance = [[self alloc] initWithConfig:config];
      });
  
      // Some other stuff here
  
      return sharedInstance;
  }
  
  + (MySingleton *)shared {
      if (sharedInstance == nil) {
          NSLog(@"error: shared called before setup");
      }
      return sharedInstance;
  }
  
  - (instancetype)initWithConfig:(RVConfig *)config {
      self = [super init];
      if (self) {
          _config = config;
      }
      return self;
  }
  
  @end
  </code></pre>
  
  <p>I am stuck with Swift:</p>
  
  <pre><code>class Asteroid {
      var config: ASTConfig? // This actually should be read-only
  
      class func setup(config: ASTConfig) -&gt; Asteroid {
          struct Static {
              static let instance : Asteroid = Asteroid(config: config)
          }
  
          return Static.instance
      }
  
      class var shared: Asteroid? {
          // ???
      }
  
      private init(config: ASTConfig) {
          self.config = config
      }
  }
  </code></pre>
  
  <p>I think I am still thinking in objective-c way and couldn't figure it out with swift. Any help?</p>