0

Is it possible to create an application that loads its initial view from a storyboard in a framework?

Let's say I have a framework, titled MyCoolFramework. This framework has a storyboard called Home.storyboard that is the initial view of an application.

Is there a way to load it into the application at launch? My AppDelegate looks like this:

import UIKit
import MyCoolFramework

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let bundle = NSBundle(identifier: "com.myprojects.MyCoolFramework")
        let homeStoryboard = UIStoryboard(name: "Home", bundle: bundle)

        let initialView = homeStoryboard.instantiateInitialViewController()

        self.window?.rootViewController = initialView
        self.window?.makeKeyAndVisible()

        return true
    }
}

It seems that at this point in the application the application does not have access to the framework or its contents. Anyone know of the proper way of doing this? This is the companion test-app for a framework I'm developing.

I have deleted the main storyboard directive in the info.plist

1 Answer 1

1

I think its likely to be the path to your framework isn't correct. You can try this (sorry Objective-C I'm sure you can convert to Swift)

[NSBundle bundleForClass: a name of your class in the framework]

Or if that doesn't work, add a method to your framework which returns the path of its own bundle and the code above as the implementation of that method.

NSBundle:mainBundle and NSBundle:bundleForClass will return different paths when called from within a framework (though if called from a library they will be the same). So experiment until you get the correct path for your storyboard.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.