There’s two ways to use your project’s code in a Playground
Playground’s Sources Folder
Yes, in Xcode 6.3 Beta 3 (and hopefully, into the future):
Playgrounds are now represented within Xcode as a bundle with a disclosure triangle that reveals Resources and Sources folders when clicked. These folders contain additional content that is easily accessible from your playground’s main Swift code. To see these folders, choose View > Navigators > Show Project Navigator (or just hit Command-1).
Open up a new playground and hit cmd + 1 to see the left pane, then drag files into the source
folder to use within the playground.
Note:
The files in the source folder are compiled to a framework which means if you want classes, functions, etc. to be accessible in the playground, they must be explicitly marked as public
.
public class VisibleClass {
}
class InvisibleClass {
}
Source: release blog
Compile Project Into Framework
- Move project to workspace if it isn’t already. (File -> Save as Workspace) will do the trick
- Add framework target to your project
- Build framework
- Make sure files you want to access are added to your framework target
- Add Playground to workspace (NOT the project)
- Use
@testable import YourFrameworkName
- Access code in playground
I made a write up here that goes into a bit more detail if you want to check it out.