elce
elce

Reputation: 312

Set 'Host Application' to None for test target, then unable to find bundle resources

Before setting Host Application to none, I had this line of code in my unit tests which gave me no problems.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

After setting it to None, I got this error.

<unknown>:0: failed: caught “NSInvalidArgumentException”, “Could not find a
storyboard named ‘Main’ in bundle NSBundle 
</Applications/Xcode.app/Contents/Developer/Platforms/
iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/Developer/usr/bin> (loaded)”

I found this post which gave me the solution. I just specified the bundle of the class I was loading the view controller in like this.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" 
bundle:[NSBundle bundleForClass:[self class]];

I'm just wondering why this happens. What is happening when I remove the Host Application that causes resources from the main bundle to get excluded?

Upvotes: 1

Views: 2269

Answers (1)

elce
elce

Reputation: 312

Nevermind I figured out why. Documentation for mainBundle says

Returns the NSBundle object that corresponds to the directory where the current application executable is located.

Since I removed Host Application, my project couldn't find main bundle directory because there's no application executable.

Upvotes: 1

Related Questions