12

Now, I have a workspace which have two project inside, one is call "ProjectOne" and the other is "ProjectTwo" as follow:

image

They have a storyboard respectively and now I want to connect two storyboard by pressing the "To Project Two" as follow:

image

but when I click the button, it show

"Terminating app due to uncaught exception 'NSInvalidArgumentException', >reason: 'Could not find a storyboard named 'two' in bundle NSBundle 8C6A5FDC9E06/ProjectOne.app> (loaded)'"

Is it possible to do that? I seeking the method for a few days but also no idea...

Peter Hornsby
  • 4,208
  • 1
  • 25
  • 44
Ivan Ngan
  • 123
  • 2
  • 7
  • 2
    A coworker of mine ran into the same issue today. It seems as though the Bundle identifier in the storyboard is ignored. This can be verified by creating an `NSBundle` instance for _ProjectTwo_ and logging its description. The description then clearly would indicate _ProjectTwo_ and not _ProjectOne_. Have you managed to find a solution? – Bart van Nierop May 13 '16 at 19:10

4 Answers4

10

You need to use the complete names of the storyboard you are including if your storyboard is in another project/module - this means including the bundle name. Please see the image below for how you would set this up in your storyboard. I have created an example setup with ProjectOne and ProjectTwo the same as your project setup.

enter image description here

The key is the information you put in the Storyboard reference. You need to include the bundle name as well! Just for reference I have included a link to Adding a Storyboard Reference

enter image description here

EDIT

While this works it leads to issues later on as you start to build your storyboard out with various scenes which are backed by view controllers, which now have to be linked to both project targets. More importantly this relationship is hidden in the project's configuration details. A better way for this to work would be to take advantage of the workspace and add a shared folder for the resources that are used by both projects.

enter image description here

Next add the shared folder to the workspace at the same level as ProjectOne and ProjectTwo. Now add a reference to the shared folder to each project by dragging it on to the project files(xcodeproj). This will add the folder to the projects target for you.

enter image description here

Now each project contains a reference to the shared folder, the sharing relationship is now explicitly shown within the project navigator.

enter image description here

Peter Hornsby
  • 4,208
  • 1
  • 25
  • 44
2

1.You can add both storyboard's Target Membership like this:
Target Membership

2.Change the name of your source files in Project two to avoid collision, check their Target Membership to Project one,configure these changes to storyboard two.

3.The AppDelegate file of Project two should be leave unchanged.

Community
  • 1
  • 1
wj2061
  • 6,778
  • 3
  • 36
  • 62
  • 1
    thanks for your help,is it any method to add the Target Membership?because i add two project in a workspace but only show one target menbership in both storyboard. – Ivan Ngan May 17 '16 at 06:48
  • 1
    I can confirm @IvanNgan's observation. – Bart van Nierop May 17 '16 at 09:11
  • @IvanNgan http://stackoverflow.com/a/37276036/3975501 <--- This solved my very similar problem. Please check, check and recheck that your bundle identifier is correct in the storyboard reference attributes inspector! Hope this will solve your problem as well! – ErikBrandsma May 17 '16 at 12:22
  • @IvanNgan I add the second project as a subproject directly, sorry for my mistake. – wj2061 May 18 '16 at 13:05
  • @ErikBrandsma it is helpful,and i have some idea now.but i also face to some problem,is it any method to find out the "real bundle"? – Ivan Ngan May 19 '16 at 07:42
  • @IvanNgan Yes, I used this to find out the cocoapods bundle: Go to your second project (general) --> select the target you want to include --> Look at the bundle-id, best copy paste this to ensure you won't make a typo ;) – ErikBrandsma May 19 '16 at 07:49
2

If Bundle you are referencing in Storyboard was never loaded before invoking Segue, system will use main app bundle. Bug or overlook on apple side?

To fix issue you have to load bundle.

let bundle = ... {your bundle here} 
if !bundle.isLoaded() {
    bundle.load()
}

Execute it at start of the app, or just make sure it runs before you attempt to perform segue.

I was bumping into this issue several times over the years, but couldn't figure out what was causing it. At one moment segue called from same ViewController in different places once worked and other did not. I was going crazy! Then I found, that the working call was preceded by manual loading some custom popup controller from this storyboard from code. It was causing load of Bundle and "magically" resolving problem for the duration of the session.

Silvertaurus
  • 384
  • 3
  • 5
  • Amazing. Note that one does not even have to load the `Bundle`; simply instantiating it is enough (that is my experience anyway). To instantiate it, I had to specify the full URL to the bundle; simply using `Bundle(identifier:)` was not enough. – Frizlab Sep 03 '22 at 12:56
  • Further comment: The `Bundle` does not have to be loaded, but the `bundleIdentifier` identifier has to be accessed. Simply doing `_ = yourBundle.bundleIdentifier` is enough AFAICT. – Frizlab Sep 03 '22 at 20:18
0

This was a solution I found for referencing a pod from a project - you can expose the bundle from the pod(or other project in your case), and then access it when you need to. It may also be worth mentioning that methods you want to access should be public.

    static var bundle:NSBundle {
    let podBundle = NSBundle(forClass: thisViewController.self)

    let bundleURL = podBundle.URLForResource("myPod", withExtension: "bundle")
    return NSBundle(URL: bundleURL!)!
    }
chamille
  • 49
  • 3