Developer Tools: How to create custom MVC module template for Xcode

Maksim Vialykh
3 min readJul 11, 2018

--

Hello dear reader. Today I want to show you how to create a template for Xcode New->File menu command.

New->File->MVC module

So, we produce a lot of files with code every day. Have you thought about how much time does it take to create a new module?

For example: MVC Architecture design requires such files as controller.swift, model.swift, modelInput.swift, modelOutput.swift, view.swift, …..

If you try create each file using context menu command New->File and then associate all of them between it takes a lot of time.

So, solution is to use a template to create module with all nesessary files associated between them.

If you want just to import completed template to your Xcode -> go to GitHub repository

Let’s get started

  • Create directory for you custom template
    Open terminal.app and execute command
    mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/Architecture
  • Execute command to open template section folder in Finder
    open ~/Library/Developer/Xcode/Templates/File\ Templates/Architecture
  • Create folder with name of your template and open it
MVC.xctemplate
  • Create TemplateInfo.plist file with the following xml
TemplateInfo.plist
  • Ok, now if you open New->File menu (cmd+N) you should see that
New->File menu
  • Ok, let’s add an icon. (size is 48px and 96px for 2x)
TemplateIcon.png
  • Add folder with module type
Fullcode module type
  • Add components files into the Fullcode folder
    All files you can download from Github repository
MVC component files
  • Try to create your first module from template (cmd+N)
New->File->MVC
MVC Module Name
MVC module complete

Congratulations! You have a completed module that created using xCode file template.

You’ve done it!

Remember, the receipt to success is continuous learning and communication with colleagues including, self-education.

This was a small guide about xCode developer tool and file templating.

In next stories we’ll discover how to create template for more strong modules.

Subscribe to my account to get notifications about new stories.

If you still have questions — write about it in the comments. I’ll answer them in future articles.

--

--