121

In Xcode, how can I find all caller functions of a specific function?

2
  • 2
    By the way, i've attached an image to my answer. and XCode versions nowadays support this. would you be willing to upvote/accept an answer, if you are satisfied with any of the answers??
    – David T.
    Nov 20, 2012 at 15:57
  • @uiroshan 's answer below is most convenient if you do this a lot (⌘+Ctrl+Shift+H)
    – drpawelo
    Apr 25, 2017 at 9:41

10 Answers 10

128

Xcode 4.5 (in beta) has this functionality. when you highlight say... a function, you can check the "caller" and "callee"

edit i believe it's located at the top left of the file panel for that file... so double click on the function to highlight it, and you click on on the file panel options (the one that has the "open recent, open unsaved...etc" drop down

EDIT #2

here's a picture to clarify (since i dont know what this menu button is called)enter image description here:

ALSO - XCode 4.5 is no longer beta, i believe, and is actually out in public

EDIT #3

also note that this caller thing does NOT search for being called under the performSelector method, as in, the particular caller that has this performSelector won't show up if you had done something like:

[self performSelector:@selector(checkIfShouldStopMovement) withObject:nil afterDelay:0.25];
2
  • 5
    It's actually View->Standard Editor->Show Related Items, see my answer (stackoverflow.com/a/13472334/888091).
    – pille
    Nov 20, 2012 at 11:38
  • 2
    @pille Ah. I see, i didn't know you can access it that way. I've upvoted your answer, and i've edited my answer to show the UI way. Thanks for the shortcut!!
    – David T.
    Nov 20, 2012 at 15:56
59

In Xcode, the quickest method is this:

  1. Select method in code (double click or mark using your mouse cursor)
  2. Press Ctrl+1
  3. Select "Callers" from the pop-up menu.

This is the shortcut for going View -> Editor -> Show Related Items in Xcode's menu.

2
  • 1
    The Callers menu is also context sensitive, so you don't have to select the method first. Just place it anywhere within the method that you want to see the callers for before invoking the <kbd>Ctrl</kbd>+<kbd>1</kbd> shortcut.
    – Jay
    Feb 21, 2013 at 17:51
  • 4
    I can't believe there isn't faster way... I am quite disappointed with the Xcode after using IntelliJ
    – stevo.mit
    Jun 15, 2015 at 14:26
50

use ⌘+Ctrl+Shift+H key combination on Xcode 7 onwards.

6
  • 2
    Beautiful solution. Thank you!
    – Myxtic
    Dec 1, 2016 at 20:00
  • 2
    Cursor must be on function name. Feb 5, 2018 at 13:55
  • 1
    In case you edited your shortcuts: search for "Find call hierarchy"
    – brainray
    May 26, 2018 at 8:13
  • 7
    I'll break my fingers to press this combination! Aug 28, 2018 at 12:29
  • Thanks, I am looking for this kind of solution. Mar 29, 2019 at 6:23
24

This can also be accessed via the assistant editor, as shown in the screenshot below. Whichever method you have the insertion point in in the main editor on the left will have its callers displayed in the assistant editor. I've found this to be the best way of looking through each caller in succession, since once you have "Callers" selected, you can then select the next caller via the next pop-up menu to the right in the jump bar.

enter image description here

2
  • This is great -- but it took me a while to figure out how to get started. For others following me: notice that in Brian's screenshot, the open drop-down is not the "Show Related Items" (ctrl+1) menu mentioned in some other answers. Instead, in the assistant editor, click on the drop-down to the right of the "Go Forward" button, and choose Callers.
    – Ashley
    Jun 18, 2013 at 16:22
  • 1
    You don't need to use the assistant editor. You can open the same menu in the primary editor.
    – funroll
    Aug 28, 2014 at 16:59
18

In Xcode-7 you have the functionality of getting call-heirerchy. Right-click on the function and click "Find Call Hierarchy": image reference:

1
  • 4
    it's called "Call Hierarchy" and the keyboard shortcut is: CTRL-SHIFT-COMMAND-H (while something is selected). Jan 17, 2016 at 10:23
11

Xcode 10 upwards seems to have made it easier. Just Command Click on the function and you should see it in the drop down.

enter image description here

1
  • shortcut key CMD+SHIFT+A
    – Mac_Play
    Feb 23 at 6:44
9

Press ⌘+Ctrl+Shift+H shortcut when a method of interests is selected (with a mouse or cursor). (as per @uiroshan 's answer)

But you can also specify any another shortcut in XCode -> Preferences -> Key Bindings

Select a method and use ⌘+Ctrl+Shift+H. But you can also specify another shortcut in XCode -> Preferences -> Key Bindings

1
  • 1
    I personally use ⌘+H (you'll have to switch un-assign it from 'Hide XCode' first. Just type "Hide" in Filter box, select it and delete with Backspace)
    – drpawelo
    Apr 25, 2017 at 10:11
4

Use Find in Project as Text or as Symbol.

AFAIK, there's no equivalent to e.g. Call Hierarchy known from Eclipse or NetBeans.

1
  • 1
    There are "caller" and "callee" in xCode.
    – user1494994
    Aug 6, 2014 at 16:38
2

Strangely the refactoring tool can detect all method calls but not the search.

So I simply use it to rename my method to a unique name (eg. reset to resetPlayer) and then use the new name in a regular textual search.

1.) Menu > Edit > Refactor... > Rename to unique name

2.) search for the new name

1
  • You can also just review all the places that would be modified in the preview, without actually finishing the refactor operation.
    – funroll
    Jun 4, 2013 at 15:55
2

The functionality is available in XCode 4.4.1, see this: http://smilingfinney.blogspot.de/2012/09/method-callers-in-xcode-44.html

Your Answer

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

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