Xcode Code Actions

shabanaa md
4 min readJun 9, 2021

--

Jump to definition doesn’t work in Xcode

Well, I ran into this issue few days ago — where Xcode’s very popular feature “Jump to definition” stopped working and it was showing a questions mark on click and I was literally annoyed with this issue, as I was too much used to use this code action for debugging — we all need this kinda code actions when working on huge code base and working with larger teams and you really don’t know which method has what hidden definitions inside.

So, One fine day it stopped working for me, all of a sudden…I tried some actually incredible & astonishing Xcode tricks to get it working like,

  • Clean build the Xcode
  • Restarting the Xcode
  • Deleting Derived Data
  • Restarting my Mac book
  • And last but not the least, deleting my project repo and re-cloning to a new location

To my surprise, non of the tricks worked :(

Let me tell you some of the reasons why the code actions will actually stop working,

  1. If you have corrupted your Derived Data
  2. Corrupted project settings
  3. The file in which you are trying to perform code actions is not actually a part of project target

And many more…

But none of the above was a reason for me, in my case it was
I had accidentally stopped indexing the my Xcode project….

Yes, my Xcode project just stopped indexing

So, after banging my head with Google for almost 3 days I finally found a solution

Now with Xcode 12.5, you cannot find the derived data folder from your Xcode organiser, so you have to go to the

Xcode preferences -> Locations -> Derived Data -> small grey icon -> Find the folder for your currently running project -> and Delete it

Additionally you will have to do one more step to get it back
Go to the .xcodeproj file of you project -> right click -> show package contents -> .xcworkspace and xcuserdata folder

Yes, you have to delete them, don’t worry if these file changes appear in your git commit, just stash the changes for mean while and you can discard the stash after issue is resolved.

Then perform the traditional Xcodian steps ;)

- close the Xcode — quit Xcode — restart your machine — restart Xcode — clean build & Done……

You will notice that Xcode started indexing again and after finishing indexing, find your Xcode actions are working finally!!!

Whooofff… long story…

Let me tell you few additional tricks on how to resolve code actions issues:

  • Sometime just deleting the Derived data would do the trick
  • You can check the respective file is added to the correct project target or not
  • Go to the Xcode preferences -> Navigation -> Command click on code -> Select the option “Jump to definition”

Go to the Xcode Preferences -> Locations -> Command Line Tools -> Select correct version of Xcode here

Bonus point:- Short cut to access Code actions from key board

A combination of ^ ctrl + command + click — it will show you the list of code actions

And a combination of command + clickwill directly jump onto the definition of the code.

So, that’s it for this story. I hope I could save at least one of your time and my experience helps you.

Thank you for reading :)

--

--