Xcode Code Templates

Source: Internet
Author: User
Tags shebang

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.