4

I tried to add some pods to the Playground within an Xcode project. Unfortunately, the only scope supported is targets since the update, and link_with is no longer supported.

ERROR:

[!] Invalid Podfile file: [!] The specification of link_with in the Podfile is now unsupported, please use target blocks instead.

When I use target blocks, I get this error:

[!] Unable to find a target named MyPlayground, did find Target_1, Target_2

OR:

[!] Unable to find a target named MyPlayground.playground, did find Target_1, Target_2

Also tried adding it within Target_1 target scope:

ERROR

[!] Invalid Podfile file: [!] Unsupported options MyPlayground for target Target_1.

What is the simplest way to add a dependency to Playground source?

Tal Zion
  • 6,308
  • 3
  • 50
  • 73
  • @EricAya Thanks, but this is not what I was looking for :), this is a workaround to the problem. I need to add the pod framework to Playground, and use the project's files as well. Your first option, just shows you how to add project files to Playground, not pods. The second option, shows you how to create a fresh and new playground with a few dependencies, again, this will bout outside of my current workspace. – Tal Zion Oct 31 '16 at 09:45
  • 1
    No worries @EricAya ;). Unfortunately option one does not solve it. You can add singel files but not a complete framework. I have found a solution based on the first one. Will post this now – Tal Zion Oct 31 '16 at 10:03

2 Answers2

8

UPDATE

As of:

Xcode 8.2

You no longer need to add your pod folder into resources, simply use it as you would in the project.

Example:

Playground


Pre Xcode 8.1

Thanks to Eric Aya, I have found a solution based on his first suggestion.

In order to add a CocoPods framework to Playground, follow these steps:

  1. Add pods to your pod file and hit pod install
  2. Add a new Playground file
  3. Click on the Sources folder in your playground
  4. Click on the + for Add Files to Sources
  5. Add you pod folder, in our case HanakeSwift
  6. Import your project pods framework import Pods_PodsPlayground
  7. Build and access your framework!

Step 3

Step 3

Step 4

Step 4

Step 5

Step 5

Step 6, 7

Step 6, 7

Tal Zion
  • 6,308
  • 3
  • 50
  • 73
  • Nice! I've added a link to this answer in a comment to my other answer - it could help others finding the right option for their specific situation. – Eric Aya Oct 31 '16 at 10:40
  • Great ;)!, glad it will help more people – Tal Zion Oct 31 '16 at 10:42
  • Doesn't work with xcode 8.2, _error: no such module 'Playground_Sources'_ – yeyo Jan 27 '17 at 08:19
  • @yeyo:-Yes, I am facing same issue.It is not working in xcode 8.2 – Donal Feb 20 '17 at 10:18
  • @Donal I managed to make it work, I don't remember exactly how I did it, but you should compile each target individually (Alamofire, SwiftyJSON ...), in other words, you must compile each pod individually before you can import them. – yeyo Feb 20 '17 at 15:27
  • Ho @yeyo & Donal , I updated my answer, please see ;). Cheers – Tal Zion Feb 23 '17 at 11:44
3

In Xcode 8.2:

  1. Click on your project name in the left column
  2. Click "New File" and choose "Playground"
  3. Import the pod that you have installed in your Podfile
  4. Possibly do a build and run to get rid of the error if it temporarily can't find the pod
  5. That's it! You should be good to go
Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151