WWDC Day 2: Importing Frameworks into Playground

My first WWDC is going awesome so far. It’s cool to be able to talk to the Apple engineers on the products they worked on, and hear how they work under the hood. I went to a couple of the lab sessions, for Swift, Xcode, and autolayout.

I was curious to get help on importing frameworks into Xcode playgrounds, and from the people at the Xcode labs I learned a couple interesting things.

  • Xcode 7: Framework search path only searches the currently selected scheme
  • Xcode 8: Undocumented feature: searches all schemes in your workspace

This answers why I was having problems importing frameworks into my playgrounds even when I added the playground into my workspace. You need to have a scheme selected which has the framework in its framework search path. If you’re using CocoaPods, they create a scheme for each pod, so you just need to select the scheme for the pod that you want to import into the playground. This won’t be an issue in Xcode 8 though, you can just import frameworks built by any scheme into your playground.
I also learned that you can create a Sources folder and Resources resources folder within a playground, allowing you to create or copy any appropriate Swift source files, or resource files.

Also another random thought: It seems like dlopen() is getting mentioned everywhere I go. At the Swift lab, when I asked about importing framworks into the Swift REPL, one idea the engineer gave me was dlopen (you can pass the -F flag to swift to import framworks) In the Optimizing App Startup Time session, they mentioned that you shouldn’t use dlopen for Dylib loading because it’s more work overall. Also there was a mention in this tweet that dlopen works in the new iPad Swift Playground. Also found an interesting read about dlopen by Erica Sadun