Xcode - Invalid character in source file (Replace " " with " ") Xcode - Invalid character in source file (Replace " " with " ") ios ios

Xcode - Invalid character in source file (Replace " " with " ")


I was having this problem. The way I solved it is by 1) copying whatever you have into Sublime Text or another code editor and having a look (you may need to enable viewing hidden characters). Mine had a code in there DC2 which is some sort of ASCII control character. For me it was caused by the fact that I had put the playground into manual execute and bound a keyboard shortcut to it that seemed to be entering that control character every time I executed it using the shortcut. I just changed the shortcut and removed the ASCII characters as I was able to see them in Sublime Text. (The link in the comments to the OP concerning left to right mode made no sense and didn't work for me.)


For me it's the ESC key - it's completely reproducible! If I go to search and hit ESC in the search window I also find the occurrences marked - and can replace those with nothing. But it's not shown even with "Show invisible"!

final solution: Bind ESC keybinding to "Cancel". It's that simple.


I encountered this problem when I was using a non-Apple keyboard with my iMac. Probably your case too. They add unnecessary control characters! One way to fix it in Xcode ischoose from the menu Editor>Show Invisibles and see if there are any unwanted characters where the error is being thrown and remove them.