4

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!

SDGary
  • 434
  • 3
  • 17
  • `NSAttributedString.Key` and `NSStoryboardSegue.Identifier` is Swift 4.2, `NSAttributedStringKey` and `NSStoryboardSegueIdentifier` is Swift 4.1. And with Source Control in Xcode it's very convenient to revert back to prior versions of the project. – vadian Oct 31 '18 at 21:59
  • `NSAttributedString.Key` is for Swift 4.2. Your issue is not with Xcode, it is not with the version of macOS. Use the correct API for your version of Swift. The best thing is to let Xcode do code completion for you. – rmaddy Oct 31 '18 at 21:59
  • @vadian Thank you for confirming this is Swift 4.2 code. I am using Git. This does compile in Xcode 10, after changing Swift Language from "Swift 4" to "Swift 4.2". Does Xcode 9.4.1 support Swift 4.2? My 9.4.1 Swift Language choices are "Swift 3.3" or "Swift 4.1" only. Have I been using Xcode 10 this whole time? I've reinstalled Xcode 10 during debug, so how do I determine my original Xcode 10 install date? Is that in an App Store log, or Xcode specific log? None of this helps my issue with Xcode printing incorrect variable values, but it's helpful, and I appreciate the help! – SDGary Nov 01 '18 at 04:46
  • @maddy How do I determine the syntax for a given method for a specific version of Swift? Is there a central document that describes changed to methods over time, or do I need to review specific Release Notes? Can you please point me to links for this information? Thanks – SDGary Nov 01 '18 at 16:33

1 Answers1

3

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.

Umberto Migliore
  • 317
  • 4
  • 17
  • Are you saying its okay to delete all files in ~/Library/Developer/Xcode/* ? If I delete these files, then run Xcode, will any needed files be recreated as needed? Essentially making this whole directory tree a cache? If so, that's great. Is there any documentation or tutorials on these files and directories? – SDGary Nov 01 '18 at 04:59
  • @SDGary No, do not delete all files from ~/Library/Developer/Xcode/. There are some things you can safely delete but there is plenty in there you probably want to keep. – rmaddy Nov 01 '18 at 15:28
  • Thanks @maddy How do I know which files / directories can be deleted, and which can't? What information here do I want to keep? How is this documented? Thanks again! – SDGary Nov 01 '18 at 16:30
  • You can clean: 1) DerivedData (a kind of cache used for faster building, Xcode will automatically rebuild it if necessary) and 2) IOS DeviceSupport that contains a folder for every release of IOS (for example mine has 12.0, 12.0.1 and 12.1: I just deleted the first two because I already updated all my devices to last version) – Umberto Migliore Nov 01 '18 at 21:01
  • @UmbertoMigliore You want to keep those older version from "iOS DeviceSupport" if you need to symbolicate crash reports from users using those other versions of iOS. See https://stackoverflow.com/questions/29930198/can-i-delete-data-from-ios-devicesupport – rmaddy Nov 01 '18 at 21:07
  • @SDGary Keep in mind that cleaning this folder up has nothing to do with your issue. – rmaddy Nov 01 '18 at 21:09
  • 1
    @UmbertoMigliore This answer helped, so I marking it correct. My problem was a bogus file at ~/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters. This caused Xcode debugger to print "FAIL" for every String. Thanks for the help! – SDGary Nov 04 '18 at 19:58