If you are like me you love writing iOS code but there is nothing that breaks your creativity more than boilerplate code and having to think about it while some other more creative solutions might reside in your mind at the same time. Even if you have a pretty good idea about your architecture it is surely a waste of time to write boilerplate since itโs just repeating code. All you need is a bunch of good templates and writing code in any architecture should be easier for you as well and easier to get into for new members of the team. But it has a catch. Xcode templates arenโt exactly what you would call a well-documented part of the tool. That is why I decided to bring you through the process of building these from scratch to save you the trouble I went through with collecting the knowledge on this subject.
Writing templates has these advantages:
- Makes you save time in the long run if you take time to maintain and write your templates well
- It takes less time to onboard new people because they will not work from scratch
- It helps maintain code conventions that you set up for yourself and your team
- If you ever wanted to export your snippets youโll notice one similarity with templates and that is that they are saved locally and outside of any project that you are working on. That means that it's a great opportunity to upload those to a repository to be able to share them or to change your workstation while keeping up to date.
#warning: all templates are dependent on GoodrequestIOSExtensions, that you can fetch with SPM from: https://github.com/GoodRequest/GoodIOSExtensions
First of all if you want to connect template to your template list you have to find the right folder to clone the repo. Directory where you can add custom templates so they are visible in your template list in xcode:
/Users/$USER_NAME/Library/Developer/Xcode/Templates
Go to the folder and clone the the git repo contents
/Users/$USER_NAME/Library/Developer/Xcode/Templates
Alternativelly you can copy the project templates and paste thme in the folder
/Users/$USER_NAME/Library/Developer/Xcode/Templates
Also if you want to create your own take inspiration from the already existing ones. Directory where to find already existing Xcode templates to take inspiration from:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File
The template automatically generated build tools package. What you want to do now is to connect it to the project as a local package.
-
Open the Package.swift you your project root and uncomment the package.swift. This will cause a compile error, but only because its still now added as a defacto package despite the fact that it is already in the right place in the project.
-
Delete the reference to these two package files.
-
Now you want to add a local package of good dependencies. Open the add package prompt for the project and click add local project. Point to the packages folder in the project root and find good dependencies. Once you select them hit add package and you are good to go
-
As soon as the packages are fetched add the package as framework
All external dependencies should be primarily added via SPM via a local package or the projects package interface. Itโs up to you which method you choose.
GoodIOSExtensions repository is released under the MIT license. See LICENSE for details.