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

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.

Related

Advice to fix 'No such module' issues for pods in Xcode project

I'm facing this No such module 'SomeModule' error in an XCode solution that I've inherited from some other developers. Initially the error is No such module 'ObjectMapper', but I find that if I swap the position of that line with the one below, it becomes No such module 'Alamofire'.
I've tried all the simple things suggested on this site (and others), making sure I'm opening the .xcworkspace file, deleting everything and re-installing (derived data, the whole Pods directory, etc.), updating cocoapods, etc.
I suspect that what's actually going on is that either the pods themselves aren't building, but for some reason the errors there are making their way to XCode's obtuse errors list, or that they are building but somehow not being linked correctly.
This is actually a project I've inherited from some other developers, so it's hard to know what weird or wonderful configuration they've done to break things. They are using an approach that I've not seen before where there's 3 build schemes for different environments (in this case Develop, Stage and Prod) then this kind of parent scheme for all the other three.
I've also tried going to 'Manage Schemes' then ticking the 'Show' checkbox for the Pods-Sunflower project. When I try to build just that project, I get a bunch of errors (mainly for Facebook, Google and Realm pods) that say things like:
Unable to load contents of file list: '/Target Support Files/FBSDKCoreKit/FBSDKCoreKit-xcframeworks-input-files.xcfilelist'
I don't expect anyone will be able to provide me a set of steps on how to solve this issue (I mean, that would be great), but I am hoping that someone can help me find ways to just work out what the problem is here, like:
How can I verify that all the separate pods are actually building?
Is there some folder where I can see all the built pods?
When you get a No such module 'SomeModule' error, where is Xcode trying to find the modules (like, in the file system? where?)
Thanks. I know this is one of those perennial issues, appreciate any advice.
The solution which worked for me was:
First thing i do when i got project from another developer is make a copy of pods and completely delete following files
Podfile
Pods folder
Podfile.lock
xcworkspace
In case you already once use that same project try deleting derived data
After deleting pods, reinstall pods and open project and let xcode do indexing of your project and after indexing look left side where warnings and errors shows, In there sometime you just have to just click and update or convert whatever xcode suggesting.
Note: - Sometimes doing same thing doesn't work try changing sequence because its xcode sometimes become dumb. Also try restarting
Honestly in these situation all i do is hit and try.
But above steps generallt works for me.

Xcode debugger displays incorrect values for variables

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.

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.

<<error type>> Strange Error

I have encountered a situation where xcode stops auto-completing and if you try to write a variable that already been defined xcode says << error type>>.
Here is my error:
I have started to see same errors after Xcode 6.1 and iOS 8.1 update. I have found that if you delete ModuleCache file at /Users/username/Library/Developer/Xcode/DerivedData/ModuleCache path, it fixes the error temporarily. And you don't have to close Xcode or the project while doing that. After deleting the file, just wait for Xcode a little to index the project files again. After that, the problem mostly resolves for some time.
As it doesn't solve the problem permanently, you should avoid writing codes causing this according to other answers till Apple solves this.
Often this indicates that your code doesn't currently compile. Swift often has trouble computing types on code that itself isn't correct. In some cases it's a bug in the compiler. Use of AnyObject can be particularly confusing to the compiler, and should be avoided as much as possible. In this case, AnyObject is required, but you should try to get it converted to a specific type quickly. Don't return [AnyType] for instance if you can possibly help it.
But the short answer is that the Swift compiler is still evolving, and it can't always work out types in complex situations, particularly on partial or (currently) incorrect code.
Note that you're using var for a lot of things that should be let. Unless you actually need to modify the variable, you should prefer let. It helps you prevent many kinds of bugs, and can be easier on the compiler to deal with (since the variable has fewer ways it can change).
<<error type>> can result from the Swift compiler not finding the header file.
Same module:
Do you have some sort of folder structure that your source code is in? If so, try setting Scan All Source Files for Includes to YES.
This will make Xcode look through all of those folders when trying to find the Header file.
Embedded Projects, multiple modules etc:
1. Check the Search Paths
Have a look where the file in which your type is defined is stored.
In your Build Settings make sure that this location is included in the Search Paths.
If it is part of the User Header Search Paths, make sure, that Always Search User Paths is turned on.
2. Check dependencies
Have a look at superclasses etc of your type. Are they included in the Search Path as well?
Found out that the error goes away and autocomplete works again if i initialised the variable like this:
var name: String = "my name"
instead of :
var name = "my name" as String
Firstly, try CMD-SHIFT-K followed CMD-R to clean and then run the build.
If that doesn't work, close XCode, delete derived data, and reopen XCode.
I faced the same issue recently. I tried running the whole project on an emulator, it resolved all the <<error type>>
I switched my build destination from Any iOS Device (arm64) to one of the available iOS Simulators, and that fixed the issue for me.
For me, simply restarting my computer resolved this issue.

XCode 4.2 Debugger Issue: Showing incorrect values + addresses for pointers

I've taken a screenshot of the compiler inconsistencies that I have been getting when creating new ViewControllers in my current project.
In this example, the debugger shows a different value for my variables 'kim', 'fakekim', and 'blah' from my log output (which shows the correct values). The debugger consistently shows the next instance variable obtaining the current instance variable's value ('fakekim' is assigned the value that 'kim' is supposed to have).
The issue seems to be project-specific. I've been able to reproduce the issue by importing my project on another Mac. However, if I create a new project, the debugger works fine. Was hoping to figure out the issue to prevent this from happening in the future.
Thanks for your help, StackOverflow community!
Edit: Larger screenshot image: http://i.imgur.com/QfZme.png
This was a (very annoying) bug with LLDB in Xcode 4.3. It has been fixed in 4.3.2.
Probably an Xcode bug. Try dragging the .xcuserstate file from you working project to your real one, and see whether that fixes it.
You could also try a clean build (shift-command-k).