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

I have a question about Xcode (Swift). Sometimes when I write an if statement. Something like this:
if(a == 2){
//do Sth
} else {
//do Sth
}
Xcode throws me an error: "Invalid character in source file"
I know it is no big deal and fixed by clicking on "Fix-it" but I want
to know what is the problem. That doesn't make sense to me...
My Xcode is on 7.2 and I am using Swift - I don't know if this is just a Swift problem.

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 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.)

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.

Editor->Show Invisibles did not show the character that was causing a problem for me. No-break-space (u00a0) will be shown as a space with no "dot" indicator. However, that's really hard to see and I completely missed it the first time. Zoom helps.
One way I found to detect invalid characters is to use Visual Studio Code and enable the settings:
"editor.renderControlCharacters": true
"editor.renderWhitespace": "all"
This has the same visibility issue with no-break-space as Xcode, however it does show other special characters.
To make it more obvious and possibly detect more invalid characters, install the extension "ascii-unicode-escape" and follow the instructions.
I don't understand why Xcode allows these invalid characters, inserts them into your source files for no reason, and doesn't even give an option to detect them! I'm trying to write code, not secrets in invisible ink, damnit!! I guess it's less of an issue for compiled code, which will show an error, but not so convenient with shader code.

I'm having the same issue. I found a solution after extensive testing. Hopefully it could save others extensive hours of researching into this terrible Xcode experience.
The problem is I have a FILCO Minila keyboard, which has the 'App' key right next to 'left arrow'. I would accidentally hit 'App' when typing really fast, and it enters a 'DEL'(Data Link Escape, Unicode 0010) invisible character. It could only be seen when copy-pasted to Sublime. It's not even visible under Xcode's own 'Editor -> Show Invisibles'(Talking about good user experience...)
Magically this doesn't happen to Sublime or VSCode, only to Xcode. So no excuses for Xcode I guess?
The fix is to download Karabiner, an advanced keymapper for macOS, and invalidate the 'App' key or map it to something else. Karabiner would also invalidate your keymapping in the system default keyboard config. So you would have to remap stuff like 'cmd', 'alt' if you've customized them. If so, be sure to map both left & right modifier keys in Karabiner, because according to Karabiner's key event viewer, the system default keymap would map left_alt & left_cmd to right_cmd and right_alt... Just annoying as hell...
It took me 2 months to realize this problem and 2 hours to actually find out it's the 'app' key that's the culprit and fix it.

I'm using XCode 10.1.
With Xcode: Xcode does not help even after showing invisibles.
Then you can copy the code to Sublime Text => you will see these invisible characters which are the <0x0f>. Click the image to see in details.
With Sublime Text 3, it works!
=> Then you know where to remove the redundancies. Hope that helps!

Are you using the option ⌥ key for any keyboard shortcuts? This was my issue. It seems combining the option key with other keys can insert hidden characters.
For me, this happened when I used the ⌃+⌥+p shortcut in Xcode to resume the SwiftUI preview canvas. It added a 0x10 character. I discovered this, as other posters have recommended, by pasting the code from Xcode into Sublime Text.
(NB: I should have been using ⌘+⌥+p).

Related

Why does Acknowledgements.plist from CocoaPods look messed up on iOS 9 and what can you do about it?

CocoaPods auto-generates the Acknowledgements.plist file so that you can include that in your settings.bundle.
Following this, I have added Acknowledgements.plist into settings.bundle.
Acknowledgements.plist looks like this:
This appears nicely on iOS 8 like this (as intended):
However, iOS 9 inserts big blank spaces between title and footerText, which makes it ugly:
It looks like this is not this file (Acknowledgements) specific and iOS 9 in general puts huge vertical spaces between title and footerText. The question is, how can you solve this situation and put nicely formatted Acknowledgements in plist?
Good observation! I noticed the same some time ago, too. Hoped that this was already fixed.
Investigation
For me some footer texts are shown correctly. Those were very short, like just two lines. The longer the FooterText is, the larger is the empty space. E.g. Realm Database has a very long license text which leads to an empty space larger than one single device screen after its title and before its Footer.
I edited the Acknowledgements.plist manually to see if the line breaks make a difference: While keeping the text as long as it is I removed the line breaks.
Results
Unfortunately removing the line breaks does not help. So it's really related to the content length. Looks like it's a TableView and the row height calculation is just far off.
However, I didn't find any workaround. Title key is limited in its length so this cannot be used as a workaround. FooterText really needs to be fixed by Apple.
I filed it under rdar://24837397
There are several other bugs in the System Settings.app which are disturbing during development:
(Crash) Open the Acknowledgements section of your App. Run a new debug build of your App via Xcode and try to switch back to the Settings.app. Due to copying a new Settings.bundle with updated Acknowledgements.plist the Settings.app crashes.
(Missing content) Open Device Settings and scroll to your App's settings, but do not open them yet. Repeat the step from above and run a new debug build via Xcode. Switch back to Settings.app and try opening your App settings: Empty settings page shown, only permissions like Core Location and Mobile Data are available. You have to close Settings.app via the task switcher to see the new content of your Settings.bundle.
Beside those two bugs it drives me nuts that Settings.app doesn't have a section index. Scrolling to my own Apps during development is an unnecessary waste of time.. I know about the new search but that's also slower that an index just for the 3rd party Apps.
Edit: If you stumble upon this, please file a Radar too! This is important to really get it fixed, see https://blackpixel.com/writing/2012/02/radar-or-gtfo.html.
This is a bug in iOS 9, the problem has been fixed in iOS 10. Unfortunately nothing can be done for users that are still running iOS 9.
If you're using CocoaPods or Carthage, AckAck works well to generate the Acknowledgements plist for you. It removes unnecessary line breaks/indentation and generates a separate plist for each framework (making it less of an issue on iOS 9).
https://github.com/Building42/AckAck
(I'm the creator of AckAck)

NSLocalizedString not working for some word

I have english, Japanese, korea Localizable.strings file. I cannot load some word from korea file. I have checked spelling, capital letter or small letter also. It is correct. I have cleaned project, reset simulator and delete app on device also. It is not working for some words. May I know how to do?
A common problem is this: If there is an error in your localisable.strings file, anything after that error will be just ignored. The line that you are checking may be fine; if the line 10 lines above is broken, it won't work. If that is the problem, for example the item in the next line isn't going to work either.
Cleaning project, reset simulator, delete app on device, are all not going to do anything for you.
Also it may be some words, that repeats. If two same keys in Localizable.strings - it may be work not properly.
Also i found, that continue key make some bugs, so i changed it to CONTINUE.
HINT something like continue_question and anything that contains continue - makes same bug.
It seems like there are another words like this. Also got to say, that i didn't delete app and clean build folder due to debag this. In Xcode 7.3 it was't necessary.
It might also be due to a blank space in one of your empty lines in the Localizable.strings file.
It's tough to spot but you can spot it by looking at which point of the file the strings start to fail localization.
Check or search for # in your localizable.String .if there is any remove it . the key value pairs below the # are not working

Xcode 6-Beta keeps crashing with a SourceKitService Terminated Editor functionality temporarily limited error [duplicate]

This question already has answers here:
SourceKitService Terminated
(34 answers)
Closed 8 years ago.
I have seen other questions with a similar problem but mine looks a bit more serious. Xcode keeps crashing on me. I have no chance to even edit a single character in my code. It is a very simple playground file with some basic code, nothing fancy. I'm not able to do anything at all in the current state.
When Xcode crashes, I hit reopen and the same thing happens again.
Locate the playground file using the Finder, then right click and select 'Show Package Content'. Next select the swift file, right click and open it using your favorite text editor (which must not be Xcode :)).
Once there, either delete its content or surround your code with comments. In the latter case, you can reopen the playground file in Xcode and selectively uncomment code line by line to know which line(s) cause Xcode to crash.
I've verified that there some recurrent patterns in code that almost always makes Xcode to crash, for example, when I use 2 or more custom operators in the same statement. I don't know if it that happens for all custom operators, or it's my specific implementation - either case, I know that I have to avoid that combination. You should take note when you notice a particular combination of code regularly making Xcode crash, and try to avoid it by splitting into multiply lines when possible.
Here's what I did to resolve it. I did reinstall Xcode a couple of times. It looks stable now but I'm not sure till when it would remain so. Looks like a bug to me. I will file it with Apple

XCode 5 shortcut to insert new line after

Now I know why people complain about xcode's editing capabilities. I find it impossible to code without touching the mouse for one thing or another and this is very frustrating. Anyway I'm used to Sublime Text so to insert a new indented line after the existing line I simply press Cmd+Return, I can't find a way to do that in xcode. Any suggestions is appreciated as I'm starting to consider appcode but don't really want to do that.
Check out this tutorial -Xcode duplicate line to add custom keyboard shortcuts in Xcode.
Then you can just add a new key-value (of your choosing):
Such as:
Insert New Line Below Current Line: moveToEndOfLine: insertNewline:
in the IDETextKeyBindingSet.plist file.
And then just configure your keybindings to the shortcut you would like (i.e.. shift+Enter, command+Enter)
You can also do this for any of your favourite shortcuts that may have been ingrained into your muscle memory from excessive use of your favourite editor. Good luck :)

Text cursor in xcode isn't typing. blinking rectangle instead of a blinking line

I'm using Xcode on a system that belonged to a former employe and I can't type. There's a weird rectangle text cursor blinking and a blank line at the bottom that responds to my key types in a weird manner. If I press a key the text cursor will just get smaller. There's also the location path of the file I'm currently on, I'd also like that to be removed. Thanks
added numbers in red next to each problem.
I suspect your former employee might have customized Xcode or, more possibly, customized the Macintosh to be non-vanilla (maybe it's a Text Input Entry setting or some internationalization or some third party extension or preference pane).
Try doing this: go to the "Text Editing" preferences within Xcode and toggle a few things to see if you have better luck. If that doesn't work, create a new user on the Macintosh and then launch and run Xcode from that new user account.
XVim.xcplugin <-- that was the file causing all of this. After deletion and relunch everything is back to normal. You can find more information about it here: https://github.com/WarWithinMe/xVim
This issue is composed by XVim.xcpluginxc. By deleting this we get free from this issue. For this issue. Please follow these steps.
1.Open the terminal.
2.Type "find ~/ XVim.xcpluginxc". This will list your entire system with this particular file/folder name.
3.From that list copy that particular path having this folder.
4.Type "rm -Rf path that you copied earlier".
5.Press "Enter".
6.type "exit".
Finally close the Terminal & Restart the Xcode.

Resources