# Create your custom playground template in Xcode

In this blog post I will show you how to add a custom playground template in Xcode. In my example I'll add a `SwiftUI View` template as alternative to the predefined `Single View` template. If you are more interested on how to create a custom file template, e.g. to be used in an iOS application, then check out my other article ["Create your custom SwiftUI file template in Xcode"](https://blog.eidinger.info/create-your-custom-swiftui-file-template-in-xcode).

![SwiftUI playground template is a custom one](https://cdn.hashnode.com/res/hashnode/image/upload/v1656546951056/ncFPhsFR2.png align="left")

The easiest way to create a new template is to copy and modify an existing template. But where are those stored? The storage location depends on the platform for which you want to create a new playground template. 

Xcode provides predefined playground templates for two platforms:
- iOS
- macOS

Playground file templates for **iOS** are stored in the `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/iOS/Playground` folder.

Playground file templates for **macOS** are stored in the `/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/macOS/Playground` folder.

Each template is a folder named with the extension `xctemplate`. I am gonna create a `SwiftUI.xctemplate` folder.

Then copy the following two files of an existing template:

1. `TemplateInfo.plist` that contains meta data information about the template.
2. `___FILEBASENAME___.playground` which is actually a package and its contents can be accessed with "Show package contents"

![The template files](https://cdn.hashnode.com/res/hashnode/image/upload/v1656547395620/5MuEO9vsN.png align="left")

The template name, visible in Xcode, can be adjusted in `TemplateInfo.plist`.

![Change display template name in plist](https://cdn.hashnode.com/res/hashnode/image/upload/v1656547738083/Wurc5j5cC.png align="left")

The code you want to change/add is located in the `Contents.swift` file.

![Contents.swift file](https://cdn.hashnode.com/res/hashnode/image/upload/v1656547382855/O4J7qbQMB.png align="left")

I am adding the following code so that my template will always create a dummy SwiftUI view and set it as the playground page's live view.

```swift
//: A SwiftUI based Playground for presenting user interface
  
import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        Text("Hello World")
    }
}

PlaygroundPage.current.setLiveView(ContentView())
```

Here is the final result:

![Final Result](https://cdn.hashnode.com/res/hashnode/image/upload/v1656549396604/UotKr0l0N.gif align="left")

