0

It seems as though my nib files are included in my test target, they don't exist in the main bundle, so my app crashes on me when I am loding a nib by its name from the main bundle. I either need to find the correct bundle that includes my nib file, or I need to load a nib using a path.

Does anyone have a solution for either one? [NSBundle bundleForClass:[self class]] doesn't work. I think the nib and class files are not in the same bundle

aryaxt
  • 76,198
  • 92
  • 293
  • 442

1 Answers1

1

It might help to enumerate the bundles

for (NSBundle *bundle in [NSBundle allBundles])
{
    // can look for resources in bundle
    locatedPath = [bundle pathForResource:resourcePath ofType:type];

    // or maybe trying and load the nib from it?
    UINib *nib = [UINib nibWithName:@"Blah" bundle:bundle];

    // check for !nil ...
}
bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • Thanks, so I found out that the crash was on UIFont, because the font I have in my nib does not exist on OSX. So this helped me go farther on my unit testing. – aryaxt Nov 05 '11 at 01:56
  • Cool - this is the approach I use to load resource files from my unit tests. In my case, I was loading fake response from a fake web server. Glad it helped. – bryanmac Nov 05 '11 at 02:44