title: XCTest fails when calling [NSBundle mainBundle]
body: <p>I have some code that calls <code>[NSBundle mainBundle]</code> at some point, mainly to read/set preferences. When I unit test the method, the test fails because the test's mainBundle does not contain the file. </p>
  
  <p>This is <a href="http://drekka.github.io/2013/10/07/XCTest-and-bundles.html" rel="nofollow noreferrer">a known issue</a>, that Apple won't fix as they consider it is <a href="http://drekka.github.io/2013/10/07/XCTest-and-bundles.html" rel="nofollow noreferrer">not a bug</a>:</p>
  
  <blockquote>
    <p>the gist of their reply is that XCTest is working correctly by returning it’s own main bundle instead of the bundle of the test target.</p>
  </blockquote>
  
  <p>Previously our codebase was using a category override on <code>NSBundle</code>'s <code>+mainBundle</code> class method to work around this. But <a href="https://stackoverflow.com/questions/9424004/suppress-warning-category-is-implementing-a-method-which-will-also-be-implement">this is dangerous because the behaviour of overriding an existing method in a category is undefined</a>. </p>
  
  <blockquote>
    <p>If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime.</p>
  </blockquote>
  
  <p>Actually Xcode warns you about it:</p>
  
  <blockquote>
    <p>Category is implementing a method which will also be implemented by its primary class</p>
  </blockquote>
  
  <p>So, what is the proper method to address the issue? </p>