Designing Your Own Project Templates in XCode 11: After the release of the new version of Xcode 9, we were provided with a nice deal of cool new features.
Some of the new features which were included in the new version are Swift 2.0, Objective C upgrades, free on device development and some sugar in debugging and testing.
An individual who is familiar with the software and has developed with the older versions of Xcode, you can notice that you now have to add the search path manually for using the third party library. Sometimes it will feel annoying adding it manually. Before Windows Xcode 7 framework search paths were automatically filled, now it has become manual after the update. There are many clients who are already facing inconvenience by the requirement for filling the Framework search path after the update.
Exploring The Features Already Present
Table of Contents
The custom project template has been created for solving the issues of manually filling the framework search path. After the struggle for solving the issue of creating a custom project template, the steps have been synthesized for creating for Xcode 7 which would help all the developers facing manual filling issues. Looking into the Xcode file structure and default project templates available in the software would give you an idea if you are new to Xcode. The first step is to go in Applications, finding the Linux Xcode option and right-click the icon. Then we need to choose the option which conveys to open package contents. This would lead you to the path towards the Mac OS default templates:
Developers- Library- Xcode- Templates- Project Templates- Mac
The above steps would direct you to the Mac OS default project templates.
Developers- Platforms- IphoneOS.Platform- Developer- Library- Xcode- Templates- Project Templates- iOS
The above one is the path that leads to the iOS default project templates.
Importance of Identifier Key
After following the path mentioned above, you are now ready to build a project template that will resemble a Single View Application template which is provided by APPLE. After the path leads you to the Applications after entering into the iOS, you need to find the Single View Application.xctemplate file. You can see a storyboard, a .plist file, and an image file. You need to open the TemplateInfo.plist file with the help of Mac Xcode, which will open and display a table with values and keys. Opening with any other text editor will display the file content with the help of XML. The most essential thing in this is the Identifier Key, which has a value of com.apple.dt.unit.singleViewApplication.
Each and every template has an Identifier key which has a name and prefix of the template. Generally Apple uses com.apple.dt.unit prefix for every template. For creating a custom project template, you need to provide your own identifier prefix.
Usage of Ancestors Key
Apart from the identifier key, there is also an Ancestor key which refers to the inheritance of the templates. The whole process is that the templates of Xcode are organized in a tree structure. The Ancestor key explains the parents of the current templates. This is, in fact, the main purpose of the identifier. When there are common properties between the templates, it allows us for referring to the template for making it possible for creating the hierarchies. Each and every template inherits some common properties which are shared with its defined ancestors. It also adds particular ones on the top of the ancestor keys. So, for making the process of creating the custom project template easier, you can plug the template in the scheme above the new template with the help of Ancestor Key. The base of our template will be on the default one except for the com.apple.dt.unit.SingleViewApplication node. This node will be replaced by our new custom made template.
Further Steps For Creating The Custom Project Template
The next step is to go to the Library- Developer- Xcode- Templates. There is a chance that there is no Template directory. In that case, you need to create one template directory. After creating the Template directory, you need to create a new folder in the name of Custom. This custom folder will represent the group in which our template will belong. This folder after creation will show up in Xcode. The folder will be seen on the right side of your new project panel with the default categories such as Framework & Library and Application.
Now you need to copy the Single View Application.xctemplace node. Then go back to Library- Developer- Xcode- Templates- Custom Directory and then you need to paste the node in the Custom Directory folder. Then now we need to change the identifier prefix after going into the .plist file.
For checking what we have created, we need to open the Xcode and in the newly created project panel, you must see your custom category along with the project template in it.
Customizations And Setup
The most common modification which can be done in a Project Template is the code modifications, build phases and build setting setup. In the build settings setup, you can modify your template which should be contained under the SharedSetting key. All the required build settings are explained in the documentation of Apple. While going through the .plist file, you can see various definitions in the SharedSettings dictionary. In this dictionary, you can include all the build settings depending upon your requirements, which include Framework_search_paths.
In the (Key Targets Key) key we can denote various project targets with properties such as linked frameworks or build settings. The (Key Framework Key) key will enable us to add different links to the frameworks, the same way you did from Build Phases- Link Binary with Library.
- How to Recover Deleted Notes on iPhone
- How to Uninstall Xcode from Mac
- Xcode Couldn’t Find Any iOS App Development Provisioning Profiles Matching
We can also add new files to our project templates and also modify the existing project templates. For the implementation of the Single View Application, there are various definitions of the View Controller class which uses the notation with the help of code implementations. We can also add another class called TestClass in our new custom template.
Basically this how you can create and modify a new custom made project template in Xcode.