When we create a new Uiviewcontroller subclass of Viewcontroller in Xcode, Xcode automatically helps us to generate part of the code (Viewdidload, didreceivememorywarning method, etc.). and comments).
Today, it took a little time to study and sort out a shell script tool that simplifies template copying and modifies suffix names in templateinfo.plist.
Script
The script is relatively simple and is not explained in detail. The template demo and the script are on GitHub.
#!/bin/bash# Write by Fenglh 2016/05/10usage() {Local prog="' basename $ '" Echo "Usage: $prog -T template file [-s suffix name]" Echo " $prog -H help." Exit 1}showhelp() {Echo "Usage: ' basename $ ':-T template file [-s suffix name]" Echo the-t template file is a directory, refer to Bmusetokenbaseapimanagerobjective-c. Directory name naming must follow: ' Class name +objective-c ' form Echo "-s suffix name displays the default suffix name when you create a new class file in Xcode" Echo "-H show this Help" Exit 1}templatefile=suffixename=classname=templatepath=/applications/xcode.app/contents/developer/platforms/ Iphoneos.platform/developer/library/xcode/templates/file\ templates/source/cocoa\ Touch\ Class.xctemplate while getopts "T:s:h"Arg Do Case $arg inchT) templatefile=$OPTARGName= 'Echo $templatefile| Awk-f'/' ' {print $NF} '' [-Z"$name"] && name= 'Echo $templatefile| Awk-f'/' ' {print $ (NF-1)} '' Classname=${name%%objective-c*}[-Z"$classname"] &&Echo "template file directory naming is not canonical"&& showhelp $; ;; s) suffixename=$OPTARG;; h) showhelp $;; ?) Usage $;;Esac Done[-Z"$suffixename"] && Usage $[ !- D "$templatefile"] &&Echo "$templatefile template directory does not exist!"Cp-af"$templatefile" "$templatepath"Cmd="add:options:1:suffixes:$classname string $suffixename"/usr/libexec/plistbuddy-c"$cmd" "$templatepath"/templateinfo.plist
Template file
Generate Template Code
Reference
Create a project template and code template for Xcode
Xcode Code Templates