Remove the space at the end of the Xcode source

Source: Internet
Author: User

Remove the space at the end of the Xcode source

When developing with Xcode, it's easy to add some space at the end of the line. When uploaded to review board, these spaces are displayed in a special color. Because a good programming style is to say, you should not add unnecessary spaces at the end of the line. If you are using Eclipse to write Java, then this time to select the written code, press to ctrl+shift+F adjust the style of the source, the trailing space is removed. Unfortunately, there is no corresponding function in Xcode.

However, we can use the command line to achieve this effect, in the project directory under the input:

""

In this way, you can put the source line in the end of the extra space removed, is not very cool? This sentence can be added to the execution of Post-review script, so that you can automatically go to the space.

By the way, I'm going to summarize these little scripting tools on GitHub, where the address is https://github.com/tangqiaoboy/xcode_tool and interested students can clone it down.

Have a good time.

June 22, 2013 update

It was written at the end of 2011 and at the WWDC conference in 2012, Apple launched Xcode4. From Xcode4, Xcode will automatically remove the space at the end of the source code. So the script mentioned above is basically useless. However, for the project HTML or JS files, Xcode to the end of the space function is not open, so at some point can have some small use.

In addition, every time you remember to knock command to remove the space is a very disgusting thing, preferably by the program automatically completed. Given the popularity of Git now, here's another way to create hooks in a git repository to get rid of all the trailing spaces at the end of the commit file, as follows:

In the catalog of the project directory .git/hooks/ , create a pre-commit file named, enter the following content

#!/bin/sh
If Git-rev-parse--verify HEAD >/dev/null2>&1;Then
Against=head
Else
# Initial Commit:diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Find files with trailing Whitespace
for FILE in ' exec git diff-index--check--cached $against--| sed '/^[+-]/d ' | sed-e ' s/:[0-9]+:.*//' | Uniq '; do
# Fix them!
Sed-i "E- ' s/[[:space:]]*$//' " $FILE"
git add $FILE"
done

chmod +x pre-commitThe file is then added with Execute permissions. This way, each time the Git commits the file, the script is automatically executed and the space at the end of the commit file is removed.

Remove the space at the end of the Xcode source

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.