1. Go to this path and add your template file:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/iOS/Source/Test Cocoa Touch Class.xctemplate
For example, Test Cocoa Touch class.xctemplate
Cocoa Touch class.xcTemplate is the system template. You can modify your own template by copying the system template.
2. Add the following script and name the file xxx.sh to the project:
#! /bin/sh # Script. Sh # UITest # # Created by July on 2020/11/27. # Copyright © 2020 July. #old_md5="${SRCROOT}/.${TARGET_NAME} templatesMD5. TXT "#old_md5=" templatesMD5. TXT" copyTemplatesfile(){# templation.xctemplate Path =$0 path=${path/ autosetup. sh/} targetFile="${path} template # targetDir = "${HOME} / Library/Developer/Xcode/Templates/UITest/Templates. Xctemplate" # system path targetDir="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/iOS/Source/Sango Cocoa Touch Class. Xctemplate "# # targetDir testing path =". / copy/Sango Cocoa Touch Class. Xctemplate" If [! -d "$targetFile"] then echo "" exit fi if [! -d "$targetDir"] then # sudo mkdir -p "$targetDir" $targetDir" sudo cp -a "$targetFile/." "$targetDir" echo" Record # # MD5 find "$targetDir" -type f | xargs MD5 - q > "$old_md5" # # for the line in $(cat "$old_md5") # # # do echo $line done} #echo $old_md5 # #if [-e "$old_md5"] #then #echo "${old_md5} "#else #echo "${old_md5}" # copyTemplatesfile #fiCopy the code
Make your own template
Copy the template file of the system and put it into the template file, as shown in the following figure: Put the template and the xxx.sh file in the same directory, and then drag xxx.sh to the terminal to run.
1. As follows: Write the above script code to the file named: xxx.sh as shown in the following figure: (pay attention to whether the path is correct) and put it in the project as follows:
2. Drag the xxx.sh file to the terminal and run it as shown in the figure below:
A computer password is required while the terminal is running
3. Check that your own template appears in the system:
4. Check whether the system is successfully added.
Create a new class in your project as follows:
4. Each controller is created in the same way as the template:
As long as you write in the template, the created document is what you can write in the template according to your own needs.