New App - Xcode Templates

When starting a new app, after deciding which based design pattern you are going to use for the views, you can create some Xcode templates to help standardize how the files are written and speed up development.

For example, let’s say we decide to use MVVM for our SwiftUI views. We also decide we will have 3 files for each view:

  • MyView_Mocks.swift
  • MyView.swift
  • MyViewModel.swift

Create the Template

We can create a basic Xcode template that creates those 3 files with some basic code inside by following these steps:

  1. Navigate to ~/Library/Developer/Xcode/Templates. (Create the Templates folder if necessary).
  2. Create a new File Templates folder inside.
  3. Create a new folder called SwiftUIView-ViewModel.xctemplate inside File Templates.
  4. Create these 4 files inside the new folder (code below):
    • ___FILEBASENAME____Mocks.swift
    • ___FILEBASENAME___.swift
    • ___FILEBASENAME___Model.swift
    • TemplateInfo.plist

After this, reset Xcode and you will see this option when adding a new file: New File

The code for the files

You can customize these files to suit your needs:

View

ViewModel

Mocks

TemplateInfo.plist

New App - Xcode Templates | manu.show
Tags: iOS tools
Share: X (Twitter) LinkedIn