Developer Tools: How to create custom MVC module template for Xcode
Hello dear reader. Today I want to show you how to create a template for Xcode New->File menu command.
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
- Create TemplateInfo.plist file with the following xml
- Ok, now if you open New->File menu (cmd+N) you should see that
- Ok, let’s add an icon. (size is 48px and 96px for 2x)
- Add folder with module type
- Add components files into the Fullcode folder
All files you can download from Github repository
- Try to create your first module from template (cmd+N)
Congratulations! You have a completed module that created using xCode file template.
Example project -> https://github.com/vialyx/mvc_in_action
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.