Lance Nelson
Lance Nelson

Reputation: 53

Changing default Xcode Playground code

I have been using playgrounds a lot while I work through a textbook, and every time I launch a new playground the default code appears:

//: Playground - noun: a place where people can play

import Cocoa

var str = "Hello, playground"

I am curious if there is any way to change the default code included when opening a new playground to something like this (for OS X):

import Cocoa

It is a small request, but having to delete the comment and Hello Playground lines of code in order to keep my playground nice and tidy gets tedious after a while.

Upvotes: 4

Views: 1091

Answers (1)

Eric Aya
Eric Aya

Reputation: 70094

There's a way but it's a bit of a hack: modify the Playground template inside the Xcode app.

Quit Xcode.

Select Xcode in the Applications folder then do "Show package contents".

Open Contents > Developer > Library > Xcode > Templates > Source > Playground with Platform Choice.xctemplate > macOS.

Select ___FILEBASENAME___.playground then do "Show package contents".

Open the Contents.swift file in any text editor then modify/remove/add what you need (make a backup copy before changing the contents).

Save the file, then relaunch Xcode and make a new macOS playground: it will use your modified template.

Upvotes: 3

Related Questions