XCodeAs a powerful IDE, it also supportsScriptFunction. Add your ownScriptWe can easily complete our work. InXCodeClick Edit User Scripts.ScriptAndXCodeThe built-in script also provides a variety of examples. For example, we addScriptAnd add a shortcut for it ?? For more information about how to add P shortcuts, see Un/Comment Selection in Comments category.Script)
- #!/bin/sh
-
- echo "%%%{PBXSelection}%%%"
- echo "#pragma mark -"
- echo "#pragma mark %%%{PBXSelectedText}%%%"
- echo "%%%{PBXSelection}%%%"
Note: Select Replace Selection from the Output drop-down list. The purpose of this script is to facilitate the establishment of # pragma. First, provide the pragma name, select the name, and press the corresponding shortcut key. # pragma is automatically completed, which is very convenient.
This script can also be written in this way, so we don't need to write echo on every line.
- #!/bin/sh
-
- cat << EOF
- %%%{PBXSelection}%%%
- #pragma mark -
- #pragma mark %%%{PBXSelectedText}%%%
- %%%{PBXSelection}%%%
- EOF
In addition to bash scripts, XCode also supports scripts in multiple languages, such as Ruby and Python.
- #!/usr/bin/env ruby -w
- # Source: http://allancraig.net/blog/?p=315
- properties = ''
- synthesize = ''
- release = ''
- STDIN.read.each do |line
- line.gsub!(/\*/, '').strip!
- words = line.split(/\s+/)
- label = words.size > 2 ? words[1] : words[0]
- variable = words[-1]
- properties << "@property (nonatomic, retain) IBOutlet #{label} *#{variable}\n"
- synthesize << "@synthesize #{variable}\n"
- release << "[#{variable.chop} release];\n"
- end
- synthesize << release.chomp
- `echo '#{synthesize.chomp}' | pbcopy`
- print properties.chomp
This script is used to help us add @ property, @ synthesize, and the corresponding release in the dealloc method. The usage is selected. member variables in the H file, for example, we select UIButton * aButton;, copy it to the location where you want to add @ property, select again, press the shortcut key to execute the script, and @ property is added, then go to the corresponding. in the m file, where @ synthesize is to be added, press? V paste, @ synthesize is also added, and the copied [aButton release];, select this line, cut and paste it into the dealloc method, it is done. Use thisScriptNot only can @ property @ synthesize be added quickly, but also some problems caused by incorrect variable names can be avoided.
Summary:XCodeDevelopment skillsUserScriptsI hope this article will help you!