Xcode custom templates

Customize the Cocoa Touch Class template

First, custom Xcode template can solve the problem

  1. The spec code is easy to read and modify
  2. Improve development efficiency

Second, the modification steps

  1. Locate the system code template location

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/

Command + N or File -> New -> File… If you look at the panel where we created the file, we can match it up

  1. Find the file we want to modify

    File types oc, SWIFT, XIBOC, XIBSwift

  2. The macro definition in file 1> ___FILEHEADER___

    • meaning

      Top of file commentCopy the code
    • The sample

      
      // ZSView.m
      // MeBaseProduct
      //
      // Created by reset on 2021/4/30.
      //
      Copy the code

    Notice the newline on the first line

    2> ___IMPORTHEADER_cocoaTouchSubclass___

    • meaning

      Import UIKit frameworkCopy the code
    • The sample

      #import <UIKit/UIKit.h>
      Copy the code

    3> ___FILEBASENAMEASIDENTIFIER___

    • meaning

      Class identificationCopy the code

    4> ___VARIABLE_cocoaTouchSubclass___

    • meaning

      Inherited parent classCopy the code

    5> ___FILEBASENAME___

    • meaning

      The string name of the classCopy the code

      The string name of a class is not the same as the class identifier

  3. Modify what we need to add

Generated effect

  1. You are advised to create a customized template folder in the iOS directory instead of modifying the system template. Copy the system template and modify it. This will create an extra column.

In this directory, you cannot modify files directly. You can copy files to the directory that can be modified and then overwrite the corresponding files