195

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?

6
  • Does this answer your question? How do you find all references to a method or property in Xcode? Sep 5, 2023 at 7:53
  • 1
    @BjörnLarsson Given the number of votes on this question and its answers, and the overall better quality of the answers, the vote should be to close it in the other direction, as a duplicate of this question. Sep 6, 2023 at 8:58
  • @MarkRotteveel I respectfully disagree. Given that both questions are equal in quality, the one posted first should have priority. Would it be possible to move answers and karma to that question? Sep 6, 2023 at 11:36
  • My rationale is that a user shouldn't loose Internet points just because someone else posted the same thing a month later. Sep 6, 2023 at 11:42
  • @BjörnLarsson Both questions are not of equal quality, and age is the least important metric to consider when determining duplicate direction. Considering that 'quality' is also something of a subjective thing, we should rely next on some other objective metrics: number of answers, number of views, score of question, general score of answers, etc. This question handily beats the other in all metrics. As for age, they were posted 1 month apart, over ten years ago. For all practical purposes, they are the essentially the exact same "age".
    – TylerH
    Sep 6, 2023 at 15:02

6 Answers 6

270
  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.
5
  • 36
    The default shortcut for bringing up the menu in ^1 so I'm usually able to press ^1, c, enter to bring up the list. Nov 21, 2013 at 22:27
  • This finds all Callers of the method and the parent implementations. Is there a way to find Callers of only this implementation? May 5, 2015 at 23:23
  • 1
    @DanielKaplan I would guess not, since in at least some cases the compiler won't have any way of knowing which implementation is to be called.
    – Mark Amery
    May 5, 2015 at 23:51
  • My method is called init, and this brings up any method named init as well. Not so smart...
    – Nathan H
    Aug 28, 2016 at 14:11
  • This is a good way, but sometimes xcode (I currently have 12.5) bugs out and this menu "Related files" only shows "Recent files" and "Locally Modified Files". In that case restart Xcode or use Command+shift+A
    – Matej P
    May 11, 2021 at 12:02
37

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

enter image description here

1
  • 1
    You don't have to use the split editor for this, although it may be convenient if you're going to be editing lots of the calling methods in quick succession. See my answer.
    – Mark Amery
    Jul 29, 2013 at 18:50
28

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

enter image description here

1
  • Analogous keyboard shortcut (that shows results in the Find Navigator panel instead of a temporary popup): [cmd]+[ctrl]+[shift]+[h]
    – ninjoncrak
    Dec 19, 2023 at 20:11
18

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

1
  • 2
    This is a slight improvement over a bare search, but it returns all references, not just the particular one you're looking for. For instance, if you have a class with a "height" property, searching for symbol references on your height property will return references to all kinds of other height properties you used, so you still have to sift through the results to find the ones you want. For a hack that works fairly nicely see this: stackoverflow.com/a/5457479/850721 Apr 13, 2013 at 12:59
7

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.

1
  • its also very useful to have a keyboard shortcut for the same, debugging gets so much quicker
    – Naishta
    May 30, 2018 at 21:28
-14

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

1
  • 16
    That answers the opposite question.
    – Richard
    Jul 11, 2013 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.