22

I am creating a pod, and in the resource bundle I have a storyboard (localised).

When I try to instantiate a storyboard, an error occurred: Could not find a storyboard named 'MyStoryboard' in bundle NSBundle. The code look like this:

NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"MyBundle" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:bundle];

MyBundle structure looks like this:

- MyBundle.bundle
  - Base.lproj
    - MyStoryboard.storyboard
  - es.lproj
    - MyStoryboard.strings

Can storyboard can be included in a bundle in the first place?

I have not seen examples of Pod that includes storyboards. If you know of any pods that share their storyboard, let me know too.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
samwize
  • 25,675
  • 15
  • 141
  • 186
  • There's an [issue](https://github.com/CocoaPods/CocoaPods/issues/2597) in the Cocoapods Repo about this. It's basically not possible to do this at the moment. – dlinsin Nov 12 '14 at 07:03
  • I faced the same issue after a long search and extensive SO browsing found a solution which worked for me, added that as an answer [here](https://stackoverflow.com/a/56643351/3876832) hope this helps someone. – pk75 Jun 18 '19 at 07:00

4 Answers4

12

There are two things to keep in mind.

  1. You add your pod resources via a predefined bundle like

    s.resources = ["Resources/Pod.bundle"]
    

in this case the content of your bundle will be copied to your xcode project without any "further processing". This means that storyboards or xib files will not be compiled and won't be available in your project.

  1. You can explicitly mention your storyboard/nib files like

    s.resources = ["Resources/**/*.storyboard"]
    

In this case the storyboard will be compiled and will be available in your project. The downside of this (at the moment of this writing) is that you can not use localized storyboards, because all storyboards will be processed and copied at the root location of your bundle. So storyboards with the same name in different .lproj folders will be overwritten.

anka
  • 3,817
  • 1
  • 30
  • 36
4

You want the resources option. Here are some specs that include theirs:

JCAutocompletingSearch/0.9.2/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.3/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.4/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.5/JCAutocompletingSearch.podspec
JCAutocompletingSearch/0.9.6/JCAutocompletingSearch.podspec
Keystone-Contacts-iOS/1.1.4/Keystone-Contacts-iOS.podspec
LumberjackConsole/2.0.0/LumberjackConsole.podspec
LumberjackConsole/2.0.1/LumberjackConsole.podspec
Mixpanel/2.1.0/Mixpanel.podspec
Mixpanel/2.2.0/Mixpanel.podspec
Mixpanel/2.2.1/Mixpanel.podspec
Mixpanel/2.2.2/Mixpanel.podspec
Mixpanel/2.2.3/Mixpanel.podspec
Mixpanel/2.3.0/Mixpanel.podspec
Mixpanel/2.3.1/Mixpanel.podspec
Mixpanel/2.3.2/Mixpanel.podspec
Mixpanel/2.3.4/Mixpanel.podspec
Mixpanel/2.3.5/Mixpanel.podspec
OpenBLE/1.0.0/OpenBLE.podspec
Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
  • Thanks. Looks like it is possible to include storyboard. I manage to include in my pod, but once I localised it (Base storyboard with strings), things don't work. – samwize Apr 25 '14 at 14:00
  • You'd have to also include the strings files if you want those in the pod as well. – Keith Smiley Apr 25 '14 at 14:32
  • I did. It's all in the bundle, and I verified the structure (refer to my post). – samwize Apr 25 '14 at 15:36
1

I solved my problem by using this line code to get bundle

let bundle = Bundle(for: type(of: self))
Varun Naharia
  • 5,318
  • 10
  • 50
  • 84
0

I currently have the same issue here. While not answering the question itself, I'd like to provide additional information that most likely is valid in your case, too:

Calling

NSString *path = [bundle pathForResource:@"MyStoryboard" ofType:@"storyboard"];
NSLog(@"path: %@",path);

will print

/var/mobile/Containers/Bundle/Application/_identifier_/MyApp.app/MyBundle.bundle/Base.lproj/MyStoryboard.storyboard

i.e. the storyboard itself is found, but not loadable "the normal way".

tilo
  • 14,009
  • 6
  • 68
  • 85