On Mar 1, 2016, at 5:00 PM, Quincey Morris wrote: On Mar 1, 2016, at 12:43 , Alex Zavatone < email@hidden> wrote:
NSString *myFrameworkIdentifier = @"com.myCompany.testFramework"; NSString *myStoryboardName = @"Insert your storyboard's name here without the extension"; NSBundle *myBundle = [NSBundle bundleWithIdentifier:myFrameworkIdentifier]; UIStoryboard *storyboardInstance = [UIStoryboard storyboardWithName:myStoryboardName bundle:myBundle]; UIViewController *initialViewControllerInstance = [storyboardInstance instantiateInitialViewController];
FWIW, I don’t think I’d do it this way either, because it’s too fragile (specifying the framework via a string).
EXACTLY.
It's incorrect. Plain and simple.
But, this allows me to move forwards in baby steps and verify that I don't destroy the universe.
This allows me to test from a client app that I can open a storyboard and have the initial view controller displayed.
As you mentioned, I do plan to have a shared instance of a framework class handle this on a class method. The *politest* API would be to implement the instantiation as a class method in a class that’s in the framework. That is, move the code that finds the correct bundle into the framework itself, along with the boilerplate that’s needed to get from storybordName + bundle to view controller.
If the class of the initial view controller is known outside the framework, that seems like a good class to put the class method into. Otherwise, you can invent a class simply to provide a namespace for the method (rather than writing a global function, which is what the method “really” is).
Realizing that I need to treat the storyboard somewhat as code and somewhat as an asset I need to pull from a bundle was very helpful. I'm now stepping in to including and asset library in a bundle to load corresponding images in a UITableViewCell for cell text.
Somehow, I seemed to pick up that frameworks can include asset libraries and the framework does by default include the Assets.xcassets as a .car file in the framework bundle, but it doesn't appear that even adding custom asset libraries to the Copy Bundle Resources build phase of the framework has any effect at all.
It's REALLY odd that to get assets in your framework, you have to add a bundle from the Mac Targets and then change it to iOS latest. This is especially true when the only docs out there are for the Mac Framework Bundle Structure, which directly states that you can have resources within your frameworks. Unless I'm doing something wrong here, which is entirely possible.
Anyway, time to get asset bundles to work. Thanks again.
|