Xcode debugger displays incorrect values for variables - swift

I previously asked a similar question here. This version has simpler example
UPDATED SUMMARY: Xcode is displaying "FAIL" in the debugger variable section for every String. Swift print() statements show correct variable values. All other data types are displaying correctly. How do I get back to a working executable?
Problem: Xcode is displaying incorrect values for variables. Originally this happened with one project. Now, EVERY project, including new projects, have incorrect variable values. Here is a screenshot demonstrating the issue in a new project (forgive my use of ViewDidLoad() as main()..)
Here's what I did: Delete Xcode.app (version 10.0). Download Xcode 10.1 from the App Store. Create a new project. Type in this code, and run.
This same problem occurs in existing projects in Xcode 9.4.1 and Xcode 10.0 -- same behavior as new installation of Xcode 10.1.
Since all versions of Xcode show same problem, I am assuming this problem is not in the Xcode executable, but in some cache or other temp file. I have cleaned my project, restarted Xcode, rebooted, etc. No help.
So my question is: How do I get a clean installation of Xcode? What directories can I delete to get to a working state? I am a novice. I have only test projects that I run in the iOS debugger or on OS X, so I am quite happy re-compiling all of my projects. Is there a complete list of temp files and directories Xcode uses?
Do I have to delete EVERYTHING Xcode has ever written to disk? I'm open to that if no other solution exists.
Thanks for any suggestions on how to proceed or how to gather more info...

I was able to solve this one after a LOT of guesswork.
I agreed with #Martin R that this didn't sound like a cache issue, since the problem persisted after downloading new versions of Xcode. I guessed that only preferences and UserData would out-live the new executable...
I reviewed the UserData directory, and found a subdirectory for the debugger:
~/Library/Developer/Xcode/UserData/Debugger/
In this directory was a file called "CustomDataFormatters". I don't know how the file got created, but here is its contents:
<?xml version="1.0" encoding="UTF-8"?>
<CustomDataFormatters
version = "1.0">
<SummaryFormatters>
<SummaryFormatter
formatString = "FAIL"
type = "Swift.String">
</SummaryFormatter>
</SummaryFormatters>
</CustomDataFormatters>
This file seems to set every string to "FAIL", which is the exact behavior I saw. Additional testing showed me that integers, floats, and other data types were displaying correctly -- it was only String type that was always incorrect.
Deleting this file solved my problem.
If anyone can explain how this file was created, I would appreciate it, but for now, I am able to debug again!
During app debug, I have right clicked on string variables to "copy" data, or "View Value as...". Did I hit some key sequence to create this file during degug?
Did I hit some weird keyboard shortcut while trying for a CMD+B or CMD+R??
Also, I changed the title of this issue to "Xcode debugger displays “FAIL” for all Strings" to help future searches.

Related

File name used twice Xcode

Error
I'm trying to use the CoreData functionality but when Xcode creates the two files (xx+CoreDataClass.swift and xx+CoreDataProperties.swift) Xcode gives me this error. The problem is: there's xx+CoreDataClass.swift is in the project's directory and in another directory that it creates when it compiles... so this error persist even if I delete the second one.
What should I do??
This is most often bugs in Xcode where it gets confused about generated files (I literally ran into this exact problem this morning....)
The solution generally is to close Xcode, delete DerivedData, and reopen Xcode.
DerivedData is in ~/Library/Developer/Xcode/DerivedData/. You can remove the whole directory, or just the subdirectory related to your project.
"Delete DerivedData" is an incredibly common solution to Xcode problems, and has been for years. Most of us have some kind of alias to simplify it. This is mine:
alias cdd='cd ~/Library/Developer/Xcode/DerivedData/'
This kind of error generated some times because of your codegen property of Managed Class. You have to change your codegen to Manual/None from attributor.

Xcode cannot find my Localizable.stringsdict file

I am trying to add pluralizable localization to my Xcode project, using Xcode 11.2.1
I followed the steps in this tutorial: https://medium.com/#vitaliikuznetsov/plurals-localization-using-stringsdict-in-ios-a910aab8c28c , which is a pretty basic instruction on how these things work. Mine, however, did not work, SO, I tried the following:
0) Actually running the tutorial code to make sure it works on my copy of Xcode. It does.
1) Copying the example Localizable.stringsdict from the tutorial into my program, and using
the keys from said tutorial in my calls, in case I had made a bad Localizable.stringsdict
or was calling it wrong. This failed.
2) Creating the Localizable.stringsdict as a property list, as some older questions suggested, instead of a Stringsdict file when creating it new, and copying the known 'good xml' of the example plist into it. This failed.
3) I tried removing all localized content from the project, and re-adding the strings file and the stringsdict file. Now it can't find either of them.
Clearly I must be missing some configuration, some step, some way of saying HEY XCODE LOCALIZE THESE. When I look at the 'Localizations' tab in the Project, there is only 1 file localized, for "Base"
Yesterday, I succeeded to localize Swift App using this tutorial.
Please try to follow this tutorial. Thanks
Number 4 was the clue here. My project has a lot of targets. Add your stringsdict file to the targets it needs to be added to. Derp.
I added the dict file to the proper target and everything works fine.
Always check the obvious stuff first.
Open your localized stringdict file, then in the right inspector click on Identity and Type you will see localization block with a button, click on it and project will recognize your file now

Xcode 10 not building latest swift file

I have updated from xcode 9 to xcode 10, after doing so when I try to change the code in one swift file the changes are not reflected when being built. I have tried the following with no success:
(1) Delete Derived Data
(2) Delete the file and re link
(3) Touch the file via terminal
I have tried dozens of solutions with no result. This issue as far as I can tell is only affecting one file. Any help will be greatly appreciated.
Xcode10 has incremental compilation mode for the debug builds. This might be affecting it. Check below link
https://shashikantjagtap.net/wwdc18-modern-tips-for-optimising-swift-build-time-in-xcode-10/
There's apparently an issue with the new build system, see related issue for details. One way around this is to switch to the legacy build system in File > Workspace Settings….

How do I completely remove all Xcode program and cache files?

Created a new question here with simpler example.
I have encountered some odd behavior from Xcode, including giving incorrect variable values and giving me syntax errors in older projects that compiled fine when I left them.
What is the best way of getting back to a clean Xcode?
Are there issues having two (or more) Xcode executables in the Applications directory? I am only running one version at a time...
Is it possible to completely remove all program data files and cache files, as if I've never installed Xcode?
If not, is there a list of caches/etc that can be safely deleted?
Here's what I've tried so far, based on Stack Overflow searches:
Clean project (CMD+OPT+K). Restart Xcode. Reboot Mac
Downloaded Xcode 9.4.1. Running this version (didn't delete Xcode
10). Can run either version
Verified Swift version was set to 4.1 (4.2 was not an option)
Deleted Derived Data folder. File> Project Settings.. Clicked on
right arrow next to Derived data folder. Deleted specific project
file. Also tried deleting entire folder
Here is my long tale of woe: I have been working on a project for about 6-8 weeks, using Xcode 9.4.1 on High Sierra. I am a novice, so I created some simple "proof of concept" apps to learn about text views, attributed strings, web views, etc. Each of these small projects compiled and ran fine.
I combining these features into a single app, and adding a Cocoa Pod library. Again, everything compiled fine. I was debugging simple issues in the code. At one point, Xcode stopped showing correct values in the Variable display for my code. I was reduced to debugging with print() statements, which always showed correct variable values.
I upgraded (?) to Xcode 10, then later to Mojave to try to resolve Xcode's incorrect variable values. Other issues emerged, including known issues with evaluateJavaScript. So I decided to revert back to pre-Mojave to get back to a working state. I used Time Machine to revert back to Xcode 10 under High Sierra.
Now my projects give compile errors. Even my simple proof of concept apps have compile errors. So I've been trying to get back to compilable code.
What else should I try to determine what has changed?
Here is the specific attributed string code that is generating syntax errors:
let titleAttributes = [NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 22)]
gives error:
Type 'NSAttributedString' has no member 'Key'
I'm also getting an error on a segue:
performSegue(withIdentifier: "showSecondVC", sender: self)
gives error
Cannot convert value of type 'String' to expected argument type 'NSStoryboardSegue.Identifier'
Apologies for the long post. Under Unix, it's easy to get a user account or app back to a known initial state. It seems a lot harder under Mac OS X...
Thanks for any suggestions!
The problems you talk seem originated by Swift version.
To answer to your question, when you download a new Xcode App (and yes, you can have more than one Xcode app in the same computer) everything is inside the huge app.
All the local data are inside the folder
~/Library/Developer/Xcode/
Where you can find several folders with lot of data. If you have problems with Ide size you could check the "IDEPreferencesController.xcuserstate" that is found inside UserData folder.

Xcode 7.3 autocomplete is so frustrating

There is a new autocomplete in Xcode. Probably might be useful because it checks not only beginning of names etc. But I found that very often it doesn't find a class name or a const name at all etc. I need to type in entire name by myself. Over all I found it makes my life harder and coding more time consuming. Is there a way to switch to the old way it used to work?
Xcode 7.3.1
In Xcode > Preferences > Text Editing
uncheck Enable type-over completions
restart Xcode
It seems that clearing the checkbox "Enable type-over completions" in XCode -> Preferences -> Text Editing does the trick. At least in my case autocompletion fell back to a sort of old way, so it could autocomplete the class name that I had to type in manually before that.
This is by no means an adequate solution, BUT it has allowed me to (barely) maintain my sanity the past few days:
After every build, you need to trash your Derived Data folder. You can find this folder in Xcode > Preferences > Locations > Derived Data. Just trash the whole thing and it'll kick off a re-indexing step that should restore proper autocomplete functionality.
Unfortunately, I've found that once I build, the autocomplete behavior reverts to its broken state.
just open Xcode derived data folder and delete the folder
/Users/yourUserName/Library/Developer/Xcode/DerivedData
then restart Xcode, now autocompletion works like a charm
I have the impression that some 'parts' of autocompletion simply fail after a while. I use to restart the Mac to get it back working. But sometimes it fails quite soon again.
Maybe the answer of #Alex Bykov combined with a restart will do the trick.
Anyway: auto-completion of Xcode always was crap. AppCode used to get it much better. Unfortunately not yet with swift.
Closed Xcode, opened Xcode, let it index, it worked.
it doesn't find a class name
As a work-around, you can try to press
Command + Shift + K and Command + B
Several times,it works temporarily.
Xcode 7.3.1
I will share another posible reason, that after couple of days we found out. We have multiple schemes, and in one of them, the bridging header was importing a file that didn't exist anymore. So, it didn't break while compiling and running (the header belongs to another scheme) but it caused the autocompletion to break (couldn't find any objective-c class).
Hope it would help someone!
After having tried different methods:
Delete Derived Data
Switching Module Enabled off in Build Settings
Full Clean
Relaunch
Only this worked:
Find any commented out (/* abc */) code after #end in your files and delete.
Credit to Max_B:
https://forums.developer.apple.com/thread/7439
In my case, other projects were auto-completing correctly. If all your projects fail to correctly predict code, then it might be a different issue, and the other answers might work.
I ran into this issue while trying to make an OS X app and I was able to fix this issue by making sure that the Xcode 7.3 documentation and the OS X 10.11.4 documentation was actually downloaded. Doing this fully restored my autocomplete functionality. My full instructions are below as well as in my answer to a similar question: https://stackoverflow.com/a/39420664/3444925
I had this problem myself and after looking through all the other similar questions & answers about this, I couldn't find a solution. However, I finally found what worked for me.
Go to Xcode -> Preferences -> Components. There you will probably find a screen that looks like the following:
This shows that the documentation has not has not been downloaded and therefore, any attempts to re-index or re-build the application without downloading the documentation would prevent you from being able to use the autocompletion functionality.
Once I downloaded the Xcode 7.3 Documentation and the OSX 10.11.4 Documentation, this was enough for me to get the autocomplete functionality back (I was trying to build an OS X app, so feel free to download as much documentation as is relevant for you).
I didn't run into this until I created a couple of new class files. Other classes worked fine, but autocomplete would NOT work for anything in the new files...
FIX (for me) - I had to add those files to ALL of my targets, including the unit test targets even though I wasn't using them yet.