Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4.5 - trailing whitespace

Tags:

xcode4.5

Latest release of Xcode (4.5) is supposed to strip trailing whitespace from source files.

But when I save a file with some spaces at the end of a line they're still there.

What am I missing?

like image 548
Snowcrash Avatar asked Sep 28 '12 16:09

Snowcrash


2 Answers

OK, here's what the problem was.

Xcode will not trim trailing white space if you add a white space at the end of the line, leave the cursor at the end of that line and then save it.

You need to move your cursor off that line and then save it.

May be some conflict between saving the position of the cursor whilst simultaneously trimming the whitespace perhaps?

like image 152
Snowcrash Avatar answered Oct 05 '22 23:10

Snowcrash


Yes, committing Xcode edited code shows trailing white-spaces in Git. Going into Xcode preferences > Text Editing : Editing (tab), you have option to include whitespaces-only lines. enter image description here

Worth to mention my current Xcode version v5.1.

Now, what about code that already uploaded in git which complaints about whitespaces?

Well, find in your editor for 4 spaces (By default in Xcode preferences > Text Editing > Indentation, indent set with 4 spaces which also can be changed ); and replace with empty string manually for those without any code in the line. You may further copy paste code in other editor (for eg TextWrangler) to see if any empty line left with 4 spaces only. "Cmd + G" is short key to "find next", helps while iterating.

like image 38
Khulja Sim Sim Avatar answered Oct 05 '22 23:10

Khulja Sim Sim