I introduced Playground Driven Development on the last project I worked on. It sped up my development and forced me to write view controllers in a decoupled way. But before I was able to reap the benefits of PDD I hit a roadblock: Xcode Playgrounds kept throwing a
Couldn't look up symbols error, because it couldn’t see Carthage-built dependencies. Here’s how to fix this issue.
Identifying the problem
Initially I wasn’t sure what the source of my Playgrounds problem was, so I made a sample PDD project without Carthage. Next I installed Carthage and added a single dependency1. This reproduced the problem:
Fixing the couldn’t look up symbols issue
I knew Playgrounds were missing some symbols, and I knew this was Carthage related. It became clear that Carthage supplied dependencies weren’t being seen by Playgrounds. What wasn’t so obvious to me is how to fix this issue in a way that wouldn’t require any kind of Xcode project restructuring.
I reached out to the iOS community with the sample project that reproduced the problem, and it turned out that Logan Moseley was having the same problem. Within a day Logan figured out the simple fix I was searching for. Thank you Logan! Here are the steps:
- Select Xcode → Project Settings → Targets → your main AppFramework target
- Click on the Build Phases tab
- Add a Copy Files phase
- Select Products Directory as the Destination
- Drag all Carthage-supplied frameworks in from the project navigator’s frameworks group
- Clean and re-build the project, open the project playground and start playing
Here’s how the new Copy Files phase should look:
We’re done. Playground Driven Development with Xcode and Carthage should now work. 💫
I’m currently writing another blog post on how Playground Driven Development improves your development experience and codebase. Stay tuned.