Reputation: 86137
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?
Upvotes: 6
Views: 5509
Reputation: 3559
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.
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.
Upvotes: 4
Reputation: 86137
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?
Upvotes: 8
Reputation: 823
Starting from Xcode 4.4 whitespaces will be trimmed automatically (default). I recommend also to activate Including whitespace-only lines.
Go to Xcode > Preferences > Text Editing > While editing
Upvotes: 1