问题描述
我正在创建一个使用我正在创建的框架的应用程序。
I'm making an app that makes use of a framework that I'm creating.
框架包含故事板,但在某些情况下,项目使用了框架将需要通过提供一个新的故事板来覆盖故事板。
The framework contains storyboards but in some cases the project making use of the framework will need to override the storyboard by providing a new one.
所以我的目标是检查中是否存在具有给定名称的故事板[ NSBundle mainBundle]
,如果没有,那么我将从我的框架中获得基本版本。
So my goal is to check if a storyboard with a given name exists in [NSBundle mainBundle]
, if not then I will get the base version from my framework.
我试过从主要包中获取故事板检查结果是否为nil但是如果找不到则抛出异常。然后我尝试捕获异常,然后从框架加载故事板。这确实有效,但感觉很脏,很可能会影响我应用的性能。
I have tried getting the storyboard from the main bundle and checking for the result being nil but it throws an exception if it can't find it. So I then tried to catch the exception and then load the storyboard from the framework. This does work but it feels dirty and it could well hit the performance of my app.
我也试过 bundle中的pathForResource
:
if([[NSBundle mainBundle] pathForResource:name ofType:@"storyboard"] != nil) {
}
但这从未发现故事板。
有没有人知道我可以检查特定包中是否存在故事板的任何其他方式?
Does anyone know of any other way that I can check if a storyboard exists in a specific bundle?
推荐答案
所以,我几乎就在那里。根据我的问题的评论,故事板的编译扩展是storyboardc。所以我可以检查一个故事板是否存在于这样的包中:
So, I was nearly there with what I was already trying. As per a comment on my question, the compiled extension for a storyboard is "storyboardc". So I can check whether or not a storyboard exists in a bundle like so:
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.
}
这篇关于如何检查特定NSBundle中是否存在Storyboard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!