0

I want to create a custom Xcode playground template for SwiftUI View. What file formats are used? How can I find examples? Where should I put those files?

DanSkeel
  • 3,853
  • 35
  • 54

1 Answers1

0

You can make template by duplicating file templates at path

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Playground

Note that each platform has it's own templates.

  1. Copy two folders TEMPLATE_NAME.xctemplate and TEMPLATE_NAME___FileMenu.xctemplate to ~/Library/Developer/Xcode/Templates/File Templates and rename them as you want.

(you can put it in subfolder SwiftUI, it's name will be used to separate your templates from others) enter image description here

  1. To change the displayed name of template you can change Name field in TemplateInfo.plist
  2. Paste the code of your template into ___FILEBASENAME___.playground file (you can use placeholders to generate code base on parameters, see for example this article)

Here are my templates as an example: https://github.com/DanSkeel/XcodeTemplates/tree/main/Playground

Note: ...___FileMenu.xctemplate files will be used when you create new file from opened playground.

DanSkeel
  • 3,853
  • 35
  • 54