1

Hi I have to access storyboard from custom framework (LoginUIModule, LoginUIModule have storyboard LoginScreen.storyboard) in app delegate. I removed Main storyboard from Main Interface and also removed name from Main storyboard file base name as well from .plist, but I getting an error

reason: 'Could not find a storyboard named 'LoginScreen' in bundle NSBundle

Note:- LoginUIModule is separate Module and I need to access it in my main (OneAppllbs) project which is a again separate module

The Code which I used in app delegate

import LoginUIModule

 self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = UIStoryboard(name: "LoginScreen", bundle: nil)
    let initialViewController = storyboard.instantiateViewController(withIdentifier: "LoginUIModuleViewController") as? LoginUIModuleViewController
    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()
Sanjay Mishra
  • 672
  • 7
  • 17
  • 1
    `UIStoryboard: init(name: String, bundle storyboardBundleOrNil: Bundle?)` - **storyboardBundleOrNil** _The bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application._ since LoginScreen is not in the main Bundle you need to pass in the LoginUIModule-Bundle. How to address this you might find in the Apple Documentation for Bundle. https://developer.apple.com/documentation/foundation/bundle – Daniel Marx Jul 23 '20 at 06:37
  • @DanielMarx thanks for you valuable comment and apple developer resources. got the solution and learn new concept as well. – Sanjay Mishra Jul 23 '20 at 06:58

2 Answers2

3

You need set Bundle to access Storyboard.

First create storyboardBundle with Bundle Identifier for framework;

let storyboardName = "LoginScreen"
let storyboardBundle = Bundle(for: LoginUIModuleViewController.self)

or referencing a class in framework:

let storyboardBundle = Bundle(identifier: "com.yourframework.id")

Then create storyboard with this bundle:

let storyboard = UIStoryboard(name: storyboardName, bundle: storyboardBundle)
Omer Faruk Ozturk
  • 1,722
  • 13
  • 25
  • how can we push new view controller which is again in different module(DashboardModule) because navigation.push() is not working – Sanjay Mishra Jul 23 '20 at 11:23
  • If you can access a class you can use it whatever you want. Please ask this as new question with the details what you want to do and did so far. – Omer Faruk Ozturk Jul 23 '20 at 11:32
0

Get storyboard from a framework

Set Storyboard ID for .storyboard. For example frameworkStoryboardId

[Access to Framework bundle]

let frameworkStoryboard = UIStoryboard(name: "SomeViewController", bundle: frameworkBundle)

let frameworkViewController = frameworkStoryboard.instantiateViewController(withIdentifier: "frameworkStoryboardId") as? SomeViewController
yoAlex5
  • 29,217
  • 8
  • 193
  • 205