I have an Xcode workspace with a dynamic framework (called 'VisualKit') and a playground, which imports VisualKit.
This setup works fine when VisualKit has no external dependencies of its own (i.e. when VisualKit does not depend on any additional dynamic frameworks).
However, when I add a dynamic framework (in this case I'm importing SnapKit, though it does not matter what framework it is), I get the following error:
error: Couldn't lookup symbols:
VisualKit.ItemsLabel.__allocating_init() -> VisualKit.ItemsLabel
type metadata accessor for VisualKit.ItemsLabel
I've tried the following: - Cleaning the project, removing the import statement, and then putting it back and attempting to rebuild the playground - Deleting derived data - Recreating the workspace/playground/framework project from scratch
...all to no avail.
My playground:
import UIKit
import PlaygroundSupport
import VisualKit
class MyViewController: UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = UIColor.red
let label = ItemsLabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello"
view.addSubview(label)
self.view = view
}
}
PlaygroundPage.current.liveView = MyViewController()
ItemsLabel (in VisualKit dynamic framework project):
import UIKit
import SnapKit
public class ItemsLabel: UILabel {
public init() {
super.init(frame: .zero)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
I would expect the playground to work the same with the SnapKit import (in VisualKit) as without.
Any ideas?
Simply click the Run button at the bottom-right of the playground, and wait for execution to complete. Xcode now compiles your code, and shows you its result. The default code doesn't output anything to the Console, but you should be able to see the value of the variable str in the sidebar on the right of Xcode.
One of the biggest differences between Swift Playgrounds and Xcode Playgrounds is that Swift Playgrounds are much less powerful and are built more as an educational tool. My biggest fear is that as Apple brings Swift Playgrounds to the Mac that they will stop supporting and growing Xcode Playgrounds.
After many painstaking hours troubleshooting this, I managed to solve it:
In Xcode, select your framework project in the project navigator.
Navigate to the Build Phases
tab.
Add a Copy Files
phase (by tapping the +
button), and select Frameworks
from the drop down selector.
Add all carthage frameworks used in your framework to the copy files phase.
Then clean and rebuild your framework and the playground should now work as you expect it to.
Note that this answer only necessarily applies if you’re using Carthage to build 3rd party frameworks used in your framework project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With