For VSCode:
You can activate the feature in Settings.
For Xcode project:
sed command can do the task.
sed
Dir.glob("**/*.swift").sort.each do |f| puts f system("sed -i '' 's/[ ]*$//' #{f}") end