Thursday, July 14, 2016

How to use Custom Framework in Xcode Swift Playground

This is a working example

(1) Open Mac Terminal and
cd ~
git clone --depth=1
cd ThisCouldBeUsButYouPlaying
sudo gem install cocoapods-playgrounds
pod playgrounds Alamofire

(2) In Xcode Build Settings, change the SDKROOT to latest iOS SDK Platform and then select Product -> Destination to iPhone 5s or above (that is simulator destination)

(3) Select Product -> Build (or ⌘B shortcut) to build the framework

(4) In Alamofire.playground, input swift code to play
import Alamofire

Important: The following conditions are required for the custom framework to work in a playground: (ref)
- The framework is in the same workspace as the playground. Use "Save as Workspace" if it is not.
- If it is an iOS framework, it is built for a 64-bit runtime destination (e.g. iPhone 5s simulator).
- The workspace contains at least one active scheme that builds a target. (avoid using legacy build location in project folder)
- The framework has already been built. (⌘B)
- If it is an Objective-C framework, sets the Defines Module build setting to Yes. If it is a Swift framework, sets to No.

The working example above is an iOS Framework for Simulator built and works for iOS Playground in the same workspace. Based on various testings, OS X Custom Framework currently does not work for OS X Playground in Xcode 7.x.

No comments: