title: Swift singleton tests
body: <p>I am trying to learn testing with Quick and Nimble and I wrote simple singleton and some tests</p>
  
  <p>Singleton:</p>
  
  <pre><code>public class LocationManager : NSObject {
  // Singleton
  public class var sharedInstance : LocationManager {
      struct Static {
          static var instance : LocationManager?
          static var token : dispatch_once_t = 0
          }
      dispatch_once(&amp;Static.token) {
          Static.instance = LocationManager()
      }
      return Static.instance!
      }
  }
  </code></pre>
  
  <p>My tests:</p>
  
  <pre><code>class LocationManagerSpec: QuickSpec {
  override func spec() {
      describe("Location manager") {
  
          let locationManager = LocationManager.sharedInstance
  
          context("initialized") {
              it("is not nil") {
                  expect(locationManager).notTo(beNil())
              }
              it("is unique") {
                  let tempLocationManager = LocationManager()
                  expect(locationManager).notTo(equal(tempLocationManager))
              }
              it("and shared instances are same") {
                  let tempLocationManager = LocationManager.sharedInstance
                  expect(locationManager).to(equal(tempLocationManager))
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>How can I test my singleton is thread safe?</p>