Sanjay Mishra
Sanjay Mishra

Reputation: 702

Accessing storyboard from custom framework not working

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()

Upvotes: 1

Views: 1201

Answers (2)

yoAlex5
yoAlex5

Reputation: 34225

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

Upvotes: 0

Omer Faruk Ozturk
Omer Faruk Ozturk

Reputation: 1852

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)

Upvotes: 3

Related Questions