While this is the default behavior, you can, at least in Xcode 7.2, check &quot;Automatically trim trailing whitespace&quot; and &quot;Including whitespace-only lines&quot; under &quot;Text Editing&quot; in Xcode&#x27;s preferences.