Find method references in Xcode

XcodeIde

Xcode Problem Overview


Is there a way in Xcode to find all the places where a method or property has been been called?

In Eclipse, for example, you can right-click a method and select Find references. Is there anything similar in Xcode?

Xcode Solutions


Solution 1 - Xcode

  1. Select the method you're interested in, or position the text cursor within it.
  2. Open the "Related Files" menu via the icon at the top-left of the Editor. (It's the button immediately to the left of the back button).
  3. Go to the "Callers" submenu for a list of all methods that call the selected method, and click any of them to jump to that file and method.

In pictures...

Screenshot of steps 1 and 2 above.

Screenshot of step 3 above

A couple of notes:

  • You can do this for properties too.

  • Note that when you select a calling method from the Callers menu to jump to where your method was called, Xcode highlights only the first call. Each calling method will only show up in the 'Callers' list once, even if it contains many calls to your method. So if you're trying to make some change at every place in your application where a method is called, be careful not to miss some in places where a calling method contains two calls to the method you're interested in.

Solution 2 - Xcode

Yes, open the Assistant editor and instead of Counterparts select Callers.

enter image description here

Solution 3 - Xcode

Select function, press cmd-shift-A, "Callers"

enter image description here

Solution 4 - Xcode

As of XCode 4.5 you can click on "Show find options" within the search field of the Search Navigator. There you can specify "Symbol References"

enter image description here

Solution 5 - Xcode

Place the insertion point in a method invocation or declaration and choose Find > Find Selected Symbol In Project. For multipart selectors this will only highlight the first part but searching does seem to work relatively reliably. You can also use Find Call Hierarchy which highlights the entire line instead.

The corresponding contextual menu item (Find Selected Symbol in Workspace) also works, but it's a bit trickier to make work properly. Make sure no text gets selected otherwise it'll search for the selected word rather than the entire selector. To do so, you can click with the left mouse button prior to clicking with the right mouse button (or Control-clicking) in the same location. There's no such issue with the contextual Find Call Hierarchy.

Solution 6 - Xcode

With xcode 4 you can now right click on references and select "jump to definition."

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJava Ka BabyView Question on Stackoverflow
Solution 1 - XcodeMark AmeryView Answer on Stackoverflow
Solution 2 - XcodeAlex TerenteView Answer on Stackoverflow
Solution 3 - XcodeUladzimirView Answer on Stackoverflow
Solution 4 - XcodeSystematicFrankView Answer on Stackoverflow
Solution 5 - XcodeNicholas RileyView Answer on Stackoverflow
Solution 6 - XcodeScott LoozeView Answer on Stackoverflow