我正在制作一个应用,该应用使用我正在创建的框架。
框架包含 Storyboard,但在某些情况下,使用框架的项目需要通过提供新 Storyboard来覆盖 Storyboard。
所以我的目标是检查 [NSBundle mainBundle]
中是否存在具有给定名称的 Storyboard,如果不存在,那么我将从我的框架中获取基础版本。
我已经尝试从主包中获取 Storyboard并检查结果是否为 nil,但如果找不到它就会抛出异常。所以我然后 try catch 异常,然后从框架加载 Storyboard。这确实有效,但感觉很脏,很可能会影响我的应用程序的性能。
我还在包中尝试了 pathForResource
:
if([[NSBundle mainBundle] pathForResource:name ofType:@"storyboard"] != nil) {
}
但这永远找不到 Storyboard。
有谁知道我可以检查特定包中是否存在 Storyboard的任何其他方法?
最佳答案
所以,我几乎已经完成了我已经尝试过的事情。根据对我的问题的评论, Storyboard的编译扩展名是“storyboardc”。所以我可以像这样检查一个 Storyboard是否存在于一个包中:
if([[NSBundle mainBundle] pathForResource:name ofType:@"storyboardc"] != nil) {
//The storyboard exists
} else {
//The storyboard isn't in the bundle, get it from the framework bundle.
}
关于ios - 如何检查 Storyboard 是否存在于特定的 NSBundle 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38590288/