Luis Corvalan
Luis Corvalan

Reputation: 53

How do you add a group in iOS playground?

In an Xcode project, files in the left Project Navigator can be organized into virtual (and actual) folders (Groups). In Playground, while a new folder can be added, it does not seems to be possible to do the same. Can it be done in Playground?

And if you can't, what would be similar?

Upvotes: 2

Views: 496

Answers (1)

azizj
azizj

Reputation: 3787

You can create an Xcode Project with a built in Playground, information found here

  1. In Xcode, File -> New -> Project… and then iOS -> Application -> Single View Application
  2. File -> Save as Workspace… Save it as SuperProject.xcworkspace in the same directory as SuperProject.xcproject file.
  3. File -> New -> File… and then iOS -> Source -> Playground. Call it SuperProject.playground, use the same directory as SuperProject.xcproject, and select the top-level “SuperPlayground” under Group (this is not the default option).
  4. File -> New -> Target… and then iOS -> Framework & Library -> Cocoa Touch Framework. Name it SuperPlaygroundiOS and uncheck Unit Tests.
  5. Optional: Control-click on ViewController.swift in the Project Navigator1 and click New File… and then iOS -> Source -> Swift File. Call it SuperClass.swift and make sure SuperProject and SuperProjectiOS are checked under Targets. Replace the contents of this file with this: import Foundation

    class SuperClass{ func greetMe() -> String{ return "Hello" } }

  6. Select the framework target (SuperPlaygroundiOS) in the File Inspector for any other files you want to access from your new playground.

  7. Select SuperPlaygroundiOS > iPhone 6S Plus beside the Play/Stop buttons, then Product -> Build.

  8. In SuperProject.playground, type the following at the top of the file:

    @testable import SuperPlaygroundiOS

  9. If you did step #5, you can now type this at the bottom of the file too.

    SuperClass.greetMe()

Upvotes: 1

Related Questions