In Xcode, how can I find all caller functions of a specific function?
-
2By 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)– drpaweloApr 25, 2017 at 9:41
10 Answers
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):
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];
-
5It's actually View->Standard Editor->Show Related Items, see my answer (stackoverflow.com/a/13472334/888091).– pilleNov 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
In Xcode, the quickest method is this:
- Select method in code (double click or mark using your mouse cursor)
- Press Ctrl+1
- Select "Callers" from the pop-up menu.
This is the shortcut for going View -> Editor -> Show Related Items in Xcode's menu.
-
1The 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.– JayFeb 21, 2013 at 17:51
-
4I can't believe there isn't faster way... I am quite disappointed with the Xcode after using IntelliJ Jun 15, 2015 at 14:26
use ⌘+Ctrl+Shift+H key combination on Xcode 7 onwards.
-
2
-
2
-
1
-
7
-
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.
-
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.– AshleyJun 18, 2013 at 16:22
-
1You don't need to use the assistant editor. You can open the same menu in the primary editor.– funrollAug 28, 2014 at 16:59
In Xcode-7 you have the functionality of getting call-heirerchy. Right-click on the function and click "Find Call Hierarchy": image reference:
-
4it's called "Call Hierarchy" and the keyboard shortcut is: CTRL-SHIFT-COMMAND-H (while something is selected). Jan 17, 2016 at 10:23
Xcode 10 upwards seems to have made it easier. Just Command Click on the function and you should see it in the drop down.
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
-
1I 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)– drpaweloApr 25, 2017 at 10:11
Use Find in Project as Text or as Symbol.
AFAIK, there's no equivalent to e.g. Call Hierarchy known from Eclipse or NetBeans.
-
1There are "caller" and "callee" in xCode.– user1494994Aug 6, 2014 at 16:38
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
-
You can also just review all the places that would be modified in the preview, without actually finishing the refactor operation.– funrollJun 4, 2013 at 15:55
The functionality is available in XCode 4.4.1, see this: http://smilingfinney.blogspot.de/2012/09/method-callers-in-xcode-44.html