Search code examples
swiftcocoa-touchsdkframeworksstoryboard

How can i use storyboard in Cocoa Touch Library


I have been able to build a Cocoa Touch library which I intend to use in presenting a ViewController in a storyboard, but it turns out that I can't access the storyboard. I keep getting an NSInvalidArgumentException error, reason: 'Could not find a storyboard named 'MyStoryboard'.

let storyboard: UIStoryboard = UIStoryboard(name: "MyStoryboard", bundle: Bundle.main)
viewController.present(cryptoTransactionViewController, animated: true, completion: nil)

Solution

  • The storyboard you're trying to access isn't in your main bundle, it's in the framework's bundle.

    So, the first thing you need to do is find the correct bundle…

    let bundleId = "com.your.bundle.id"
    guard let bundle = Bundle.allFrameworks.first(where: { $0.bundleIdentifier == bundleId}) else {
        fatalError("Failed to find bundle with identifier \(bundleId).")
    }
    
    let storyboard: UIStoryboard = UIStoryboard(name: "MyStoryboard", bundle: bundle)