在将 Host Application 设置为 none 之前,我的单元测试中有这行代码,没有给我任何问题。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
将它设置为 None 后,我得到了这个错误。
<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)”
我找到了 this post这给了我解决方案。我只是指定了我正在加载 View Controller 的类的包。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:[NSBundle bundleForClass:[self class]];
我只是想知道为什么会这样。当我删除导致主包中的资源被排除的主机应用程序时会发生什么?
最佳答案
没关系,我想出了原因。 mainBundle 的文档说
Returns the NSBundle object that corresponds to the directory where the current application executable is located.
自从我删除主机应用程序后,我的项目找不到主包目录,因为没有应用程序可执行文件。
关于ios - 将测试目标的 'Host Application' 设置为 None,然后无法找到捆绑资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38476885/