XCode notes UserScripts tips

Source: Internet
Author: User

XCodeStudy NotesUserScriptsSkill Application is the content to be introduced in this article, mainly to learnXcodeMediumUserScripts. As a powerful IDE, XCode also supportsScriptFunction. Add your own feetBenWe can easily complete our work.

Click Edit User Scripts in XCode to easily addScriptIn addition, the scripts provided by XCode provide us with a wide range of examples. For example, we add a script like this and add a shortcut key for it ?? For the P shortcut key addition method, see the Un/Comment Selection script in the Comments category)

 
 
  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. ThisScriptThe role is to facilitate the establishment of # pragma, first provide The pragma name, then select this name, and press the corresponding shortcut key, # pragma will be automatically completed, 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.    
  3. cat << EOF 
  4. %%%{PBXSelection}%%%  
  5. #pragma mark -  
  6. #pragma mark %%%{PBXSelectedText}%%%  
  7. %%%{PBXSelection}%%%  
  8. EOF 

In addition to bash scripts, XCode also supports scripts in multiple languages, such as Ruby and Python.

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

TheScriptThe function is 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:XCodeStudy NotesUserScriptsThe tip application is completed. I 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.