Reputation: 1168
Let's say I have 2 frameworks:
MyApp.framework has a storyboard that uses classes from FancyLabels.framework.
If I create an app target that links and embeds both frameworks, I can instantiate view controllers from MyApp.framework no problem.
But if I try and instantiate a view controller from MyApp.framework in a playground, it can't find the classes from FancyLabels.framework.
My playground code:
//: Playground - noun: a place where people can play
import UIKit
import MyApp
import FancyLabels
let bundle = Bundle(for: MyAppViewController.self)
let storyboard = UIStoryboard(name: "Main", bundle: bundle)
let vc = storyboard.instantiateViewController(withIdentifier: "MyAppViewController")
let view = vc.view
The output in the console:
2017-01-22 19:18:17.016 MyPlayground[98260:3124481] Unknown class _TtC18FancyLabels11StyledLabel in Interface Builder file.
2017-01-22 19:18:17.037 MyPlayground[98260:3124481] Failed to set (styleString) user defined inspected property on (UILabel): [<UILabel 0x7fcf175017c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key styleString.
Upvotes: 1
Views: 298
Reputation: 1168
Finally figured this out. The issue was that my "FancyLabels" framework was using a prebuilt framework via Carthage (XCGLogger). The solution was to follow the appropriate steps to use a Carthage framework in a playground, namely to add the framework's project from Carthage/Checkouts to my workspace and build it. Then everything works as expected, even the playground that is inside the framework project, with full usage of FancyLabels in the MyApp framework's storyboards/xibs.
For people coming to this question that are strugging with setting this up even without Carthage, I've done a quick working example of how to set this up here: https://github.com/mfclarke/NestedFrameworksInPlaygrounds/
Upvotes: 0
Reputation: 2307
I've struggled to find the best approach for this as well :(
The best solution I've found is to create a blank/empty workspace where you can add your framework (just drag them into the workspace like you would adding to a regular project) and then also add the playgrounds to the workspace.
Instead of opening up the playgrounds, you then open up the workspace and use the playground within that context.
The first time you open the playground in the workspace you'll get an error saying that the framework can't be found, but after running build
the framework is available.
Another gotcha is that while you're accessing the framework from this workspace, any other projects using the framework will also need to be closed.
If you want to check out an example setup, you can see the 'Playgrounds' folder in my project here: https://github.com/mathewsanders/Mustard/tree/master/Playgrounds
Would love to hear if other people have found better approach that this because the limitation of having to close other projects while using the workspace is quite annoying.
Upvotes: 2