Some automated processing scripts useful for iOS development

Source: Internet
Author: User

Recently I have compiled two scripts to assist iOS development for some automated processing.

Introduction Objective-C method name formatter

Due to some changes in work, IOS was developed on a 21-inch iMac screen some time ago, now I have bought a MacBook Pro and developed it in my notebook (I was developing it on a 19-inch black apple display earlier ). This screen size change may cause some code indentation based on the original screen size and line breaks on another screen to look messy.

Anyone familiar with the obj-C syntax knows that its method definition syntax makes it sometimes look much longer than the method signature in other languages. In this way, a 13-inch notebook always looks awkward (although it supports method definition and line breaks, when xcode creates a file, it does not wrap the default method names that contain multiple parameters ). Using the default code formatter of xcode does not seem to have a line feed on the parameters of the method (even if there is a historical problem such as an existing project, one file and one file are manually executed for the formatting command, it's also tiring)

So I wrote a script specifically used to do this.

It is based on the configured project path:

#TODO: change the path to your xcode project pathGLOBAL_PROJECT_PATH     = '/Users/yanghua/Desktop/weiboDemo'

To match the file type with a specific Suffix:

#want to match GLOBAL_INCLUDE = ['*.h', '*.m']

Of course, to be careful, you may not want to touch the library files that you introduce from the outside, this is also supported here (you only need to enter the relative path of the folder to be excluded or the relative path of the file ):

#want to exclude               GLOBAL_EXCLUDE = [] 

Then, it will traverse all the matched files, open them, traverse all the rows, and use the regular expression to match the signature method.

Note: here, the regular expression is written according to the obj-C syntax. After formatting two projects with this script, no syntax error is found during compilation. I am a newbie. If you have a better way of writing, please don't hesitate to give me some advice!

#match method pattern#\s                 :space#\s*                :0 or n space#([\d\w]*)          :0 or n number or char such as (void) / ( CGFloat)#(([\d\w]*)\s*\**\s*):  such as: (NSString* ) / ( UITableViewController *)#\(                 :match left '('#\)                 :match right ')'GLOBAL_METHOD_PATTERN   = '^\s*(-|\+)\s*\(\s*(([\d\w]*)\s*\**\s*)\s*\)\s*'#match notation and postilGLOBAL_UNUSED_PATTERN   = '^\s*(//|//*)\s*'

Notes:

(1) match all method names

(2) If there is no method or only one parameter, no processing is performed.

(3) If there is more than one method parameter, any parameter label starting from the second parameter will not be processed if there are more characters than the first segment of the method name (because of this line, cannot be aligned based on colons)

(4) do not process the annotated method name.

(5) method calls are not processed temporarily (too complicated)

(6) other method signatures will be matched with lines for processing

Example:

-(CGFloat) getHeightWithText:(NSString*)text fontSize:(CGFloat)fontSize constraint:(CGSize)cSize minHeight:(CGFloat)mHeight;

To:

-(CGFloat) getHeightWithText:(NSString*)text                        fontSize:(CGFloat)fontSize                      constraint:(CGSize)cSize                       minHeight:(CGFloat)mHeight;

SVN missing-file warning processor recently writes a project, although the IOS end only has one. However, I still tried the "Source Control" function provided by xcode and used SVN for version control. It is okay to use (because it is only a person checking in/out), but still encountered some problems. Bug generation process: 1. the project is under SVN version control. 2. (Optional) Add a file to the project and add Version Control (a) 3. delete a file from the project, and select move to trash4. during compilation, wraning prompts that the previously deleted file (missing file XXXX) is missing. In addition, a file is under version control, modifying the file name also produces missing file warning details and processing methods. For details, refer to this article! For this problem, refer to its solution. I also wrote a script to handle it. There is nothing to say, that is, the command line command of SVN is used. Under the normal SVN operation policy: if the above problem occurs, go to the project path under Terminal and run "SVN status". Then, the files with "missing" will be preceded by "? ". (Note: Isn't this the case ?, So I am saying that under normal SVN operations, it cannot be controlled due to special circumstances ). The script matches? But does not contain the project file --. xcodeproj. Find it and delete it! Run the command line

./Users/yanghua/Desktop/Python/objcFileHandler/objcMethodFormatter.py

Xcode built-in per/post-action run [recommended] Step 1: Step 2: You can configure any scheme on the left, and they implement blocking similar to the idea of "AOP. This allows you to add pre-actions and post-Actions interference before and after an action. Click "+" to create a running script. Step 3: select target and enter the script path to be run. In this way, each time you execute a specific scheme (such as the build here), it will be executed once, and even if there is a problem with the script, it will not affect the main action (build ). I personally think that xcode provides such a function very well. The source code written in the last two scripts is submitted to my GitHub. If necessary, you can use it on your own. In addition, if you have a good idea, you are welcome to provide it! Https://github.com/yanghua/objc-xcode-Hack-Handlers
Related Article

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.