title: iOS Testing: dispatch_once get called twice. First in App, second in Test. Problems with Observers
body: <p>I have a singelton class which will be create in the app delegate.</p>
  
  <p>When i run XCTTests then its get create a second time.</p>
  
  <pre><code>+ (instancetype)urlSchemeManager
  {
      static dispatch_once_t onceToken;
      static UrlSchemeManager* _sharedInstance;
  
      dispatch_once(&amp;onceToken, ^{
  
          _sharedInstance = [UrlSchemeManager new];
  
  
      });
      return _sharedInstance;
  }
  </code></pre>
  
  <p>This is resulting in two different instances. This was no problem if i just use it for unit test.
  But in the integration test, when i register an observer for urlSchmemeManager i get a EXC_BAD_ACCESS, because it was already observed by the rootViewController (in the UI).</p>
  
  <p>In RootViewController:</p>
  
  <pre><code>UrlSchemeManager * schemeManager = [GlobalSpace globalSpace].urlSchemeManager;
  [schemeManager addObserver:self forKeyPath:OBSERVER_KEY_URL_SCHEME_MANAGER_CONTENT_MORE options:NSKeyValueObservingOptionNew context:nil];
  </code></pre>
  
  <p>Does anyone has an idea how i can get around this problem?</p>