Home

Awesome

đź•Ť Xcode templates

iOS Version Swift Version

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:

Table of content

#warning: all templates are dependent on GoodrequestIOSExtensions, that you can fetch with SPM from: https://github.com/GoodRequest/GoodIOSExtensions

Installation

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

Git clone

Go to the folder and clone the the git repo contents

/Users/$USER_NAME/Library/Developer/Xcode/Templates

Copy paste

Alternativelly you can copy the project templates and paste thme in the folder

/Users/$USER_NAME/Library/Developer/Xcode/Templates

Create your own 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

Loading Dependencies with SPM

The template automatically generated build tools package. What you want to do now is to connect it to the project as a local package.

  1. 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.

  2. Delete the reference to these two package files.

  3. 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 Logo

  4. As soon as the packages are fetched add the package as framework

Logo

External Dependencies

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.

License

GoodIOSExtensions repository is released under the MIT license. See LICENSE for details.