XCode learning skills-User Scripts

Source: Internet
Author: User

XCodeLearning SkillsUser ScriptsIs the content to be introduced in this article,XCodeAs a powerful IDE, it also supportsScriptFunction. Add your ownScriptWe can easily complete our work.

InXCodeClick EditUser ScriptsEasy to addScriptAndXCodeBuilt-inScriptIt 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)

 
 
  1. #!/bin/sh  
  2.    
  3. echo "%%%{PBXSelection}%%%"  
  4. echo "#pragma mark -"  
  5. echo "#pragma mark %%%{PBXSelectedText}%%%"  
  6. 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.

 
 
  1. #!/bin/sh  
  2. cat << EOF 
  3. %%%{PBXSelection}%%%  
  4. #pragma mark -  
  5. #pragma mark %%%{PBXSelectedText}%%%  
  6. %%%{PBXSelection}%%%  
  7. EOF 

Besides bashScript,XCodeIt also supports Ruby, Python, and other languages.ScriptFor example, this RubyScript

 
 
  1. #!/usr/bin/env ruby -w  
  2. # Source: http://allancraig.net/blog/?p=315 
  3. properties = '' 
  4. synthesize = '' 
  5. release    = '' 
  6. STDIN.read.each do |line  
  7.     line.gsub!(/\*/, '').strip!  
  8.     words = line.split(/\s+/)  
  9.     label = words.size > 2 ? words[1] : words[0]  
  10.     variable = words[-1]  
  11.     properties << "@property (nonatomic, retain) IBOutlet #{label} *#{variable}\n"  
  12.     synthesize << "@synthesize #{variable}\n"  
  13.     release << "[#{variable.chop} release];\n"  
  14. end  
  15. synthesize << release.chomp 
  16. `echo '#{synthesize.chomp}' | pbcopy`  
  17. print properties.chomp 

TheScriptThe function is to help us add @ property, @ synthesize, and the corresponding release in the dealloc method. The usage is to select the 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, and press the shortcut key to executeScript, @ Property is added, and then to the corresponding. m file, in the position where you want to add @ synthesize, 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:XCodeLearning SkillsUserScriptsI hope this article will help you!

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.