13

I'm new to iOS development and using Xcode and I'm having trouble getting Alamofire to work within a Playground. There's some functionality I'd like to test out for proof of concept but the library is not linked to the Playground and I've tried getting it to play nicely. I have Alamofire set up to work within an iOS (not in a Playground) project before the installation instructions in the Github Alamofire repo were recently updated.

Any suggestions on how to get Alamofire to import properly in the Playground?

Petesta
  • 1,623
  • 3
  • 19
  • 29
  • 1
    possible duplicate of [How to I import 3rd party frameworks into Xcode Playground?](http://stackoverflow.com/questions/24046160/how-to-i-import-3rd-party-frameworks-into-xcode-playground) – mattt Oct 02 '14 at 01:36
  • Please see: http://stackoverflow.com/questions/29882996/how-to-use-frameworks-imported-with-carthage-in-swift-playground – Richard Kruse Nees Apr 18 '17 at 15:32

4 Answers4

6

Apple provides excellent step-by-step instruction to do so here: Importing Custom Frameworks Into a Playground

Craig
  • 9,335
  • 2
  • 34
  • 38
Canucklesandwich
  • 693
  • 6
  • 15
  • 2
    Now moved to here: https://developer.apple.com/library/ios/recipes/Playground_Help/Chapters/ImportingaFrameworkIntoaPlayground.html – Chris Conover Jul 03 '15 at 00:29
  • 5
    And now apparently moved to here: https://developer.apple.com/library/prerelease/ios/recipes/Playground_Help/Chapters/ImportFramework.html – Alex Shaffer Oct 08 '15 at 18:09
  • 2
    any idea where it now is? urls seem to all point to http://help.apple.com/xcode/mac/8.0/ now :( – Danoram Oct 14 '16 at 12:39
5

Here is what I consider to be the simplest straight line path:

Download and build Alamofire:

brew install carthage
echo "github \"Alamofire/Alamofire\"" > Cartfile
carthage update

Configure the workspace with a playground file and Alamofire.

  1. From the Carthage/Build/{iOS / OSX} directory, drag the Alamofire.framework file into your link library list: {Project Name} -> {Target Name} -> Build Phases -> Link Binary With Libraries
  2. Command-N (create file) -> {Platform} -> Source -> Playground
  3. If not already in a Workspace file, File -> Save as Workspace. To be paranoid, I close the project / workspace and (re)open the workspace.
  4. Click on the playground file created in #2, and add the import import Alamofire
Chris Conover
  • 8,889
  • 5
  • 52
  • 68
  • From all I read so far this should be the right way. Doesn't work for me with Xcode 7b6 though. I even tried adding the `Alamofire.xcodeproj` to the workspace without success. The playground just wont find the framework. – stigi Aug 29 '15 at 14:47
  • Have you made sure the binary is being built with 7 - you have set xcode-select correctly? – Chris Conover Aug 30 '15 at 16:56
  • I have also tried these steps without success using xcode 7 GM. Any other ideas? I had this working a couple beta versions ago. – araMara Sep 10 '15 at 22:07
  • @stigi, @AJEzk: Make sure you are pulling the right branch - double check with Alamofire, but it might be `github "Alamofire/Alamofire" "swift-2.0"` – Chris Conover Sep 10 '15 at 22:15
  • Doesn't work for me. I have a playground within a project that has the Alamofire.framework. The project is okay...can see the framework. But the member playground can not. Furthermore, I would like to have a stand-alone playground accessing the framework without need of a host project. – Frederick C. Lee Aug 27 '16 at 20:05
0

You can try moving library to

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/

Then you can import and use it right in your playground

Nikita Zernov
  • 5,465
  • 6
  • 39
  • 70
0

You can create a playground within the project also like in this tutorial

Steps

  • If the project is not in a workspace, save as workspace
  • Create new Playground, by adding to workspace level in the project pane
  • Ensure your project has a framework target. If it doesn't Edit the scheme to add a new Cocoa Touch Framework target (it doesn't need to have unit tests)
    • Add the files that you want to use in the playground, to the new framework target
  • Build the Framework by selecting the target in the build box at the top
  • In the playground, import the Framework. If the classes you want to use are not public, you need to import like so: @testable import ModuleFramework
Efren
  • 4,003
  • 4
  • 33
  • 75