Xcode find caller functions - xcode

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

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];

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.

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

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.

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

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

Use Find in Project as Text or as Symbol.
AFAIK, there's no equivalent to e.g. Call Hierarchy known from Eclipse or NetBeans.

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

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

Related

Is there a way to jump to the target/scheme selection menu in Xcode?

I know the keyboard shortcuts for most things I often do in Xcode, but there is one thing I still haven't figured out:
How do I switch the active target/scheme without using my mouse?
I can switch from the previous and next scheme by using CTRL+COMMAND+[, but I would really like to expand the menu and type the scheme I want, similarly to how I can expand the methods navigator with CTRL+6.
Ctrl+0 will show a list of schemes. Then all you need to do is type a name of a scheme and hit enter.

how to come back when you are reading code in Xcode?

I have been developing in zend studio and there is a feature I miss a lot in Xcode. When you are reading code in a main function and you want to go in a specific function to read something, you can click in the left area of your current line of code were your are, and a flag-mark appears in that line of code, so you can go anywere else in the code and it will be very easy to come back to that line of code you were before because there is a flag and you only have to click on it and you automatically go back. Does Anybody know a similar way to do this in Xcode?
Unfortunately, this feature was present in earlier versions of Xcode (up to Xcode3 IIRC) and was called "Bookmarks", but it was removed since then.
You can use breakpoints (and disable them) as a workaround, even if it's not perfect. I personally prefer using other tricks, like "Open Quickly" and named tabs.
Alternate trick 1 : "Open Quickly"
One trick is to use Command+Shift+O (or "File" menu > "Open Quickly") to quickly open a file. In the field that appears, you can type:
The name or parts of the name of a file.
Typing "MainViewController" will propose to jump to the MainViewController.h or MainViewController.m file.
Typing "MainVC" will work too, as well as "MainViewCtrl", as long as the order of the letters you type is the same as the full name.
Very handy to just type "ContTVCell" to open the ContactsTableViewCell.h file that is hidden deep in subgroups of my project for example
Similarly, you may also type the name or parts of the name of a symbol, especially a method name.
For example, typing tvcellforrow will list you all the definitions of -tableView:cellForRowAtIndexPath: it could find in your project and let to jump to the one you want
When typing (parts of) the name of a file, adding : followed by a number at the end will allow you to directly jump at the corresponding line
For example, typing mvc:50 will propose you to jump to line 50 of MainViewController.h or MainViewController.m
Another trick : using (named) tabs
Don't forget that you can open tabs in Xcode, which can be very handy in this kind of situation.
When you are editing a file at some interesting position, you can create a new tab to browse elsewhere and go at any other place… and then go back to your first tab to find the code where you left it at the time you switched to the other tab.
Don't forget that you can name your tabs (simply double-click on their title) to give them a more explicit title. You may then quite think of them as "named bookmarks" somehow
Likewise, don't forget that you can detach tabs in separate windows too, if you prefer (for example to keep them around and visible on your secondary screen while you edit another part of your code)
You can even combine this with the "Open Quickly" trick presented above: once you made the "Open Quickly" field appear and typed something into it, instead of just validating using the enter key:
use Alt+Shift+enter to let Xcode present you a small widget that let you choose where you want the file to open (in the current tab, in another tab, in the assistant editor, in a dedicated window…)
use Alt+enter to open the file using the alternate navigation defined in Xcode preferences (Xcode > Preferences > Navigation > Optional Navigation). By default, the behavior when opening a file while using the Alt key is to open the file in the Assistant Editor. Personally I changed that in my Xcode preferences as I prefer to make Xcode open the file in a separate tab instead, which makes Alt+clic much more useful.
Sure, all those tricks with "Open Quickly…" and "Tabs" do not replace the bookmarks feature that you are missing. But they are still nice alternate ways to jump quickly to any position in your code, even any specific line of any specific file in your project, wherever you are in Xcode (even without having to have the Project Navigator visible on the left part of your window), and let you have multiple editors in different tabs to go quickly back to a part of interest in your code
its on top of your editor i have added two pics just check them.
When you navigate to another place in Xcode, say, open a different file, or Command-click and jump to definition, you can go forward and back by swiping right or left on the trackpad with two fingers.
You can also use keyboard shortcuts: Ctrl+⌘+→ to go forward, or Ctrl+⌘+← to go back.
Finally, you can click triangular buttons at the top left in your edit area.
There is a go back button at the top left of the editor!
If that is not good enough, whar I do is misuse breakpoints to set flags in my code. The breakpoint navigator thus becomes a table of flags. It isn't much but there you are.

XCode 4 -> Quick way to jump (or switch) to super class

If we press ctrl+command+up arrow we switch between file code and header code. (.m to .h)
If we press ctrl+command+j or command + mouse click we jump to definition of variable. But it not work for super.
So, there are a fast way to do it?
I'm a little late to the party, but here's a good method for seeing both superclasses and subclasses. Click on the related files icon. It looks like this: and you'll find it in the upper left of the edit window. You'll get a menu of many kinds of related files among which will be the superclass and subclass lists.
You can also open that menu using Ctrl+1, if you happen to be a keyboard person.
Try Command + Shift + D. Jump to definition. Does that work?
Also check out the link bellow. It lists a bunch of Xcode keyboard shortcuts.
http://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/xcode_help-command_shortcuts/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40010560-CH1-SW1

Find method references in Xcode

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?
Select the method you're interested in, or position the text cursor within it.
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).
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...
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.
Yes, open the Assistant editor and instead of Counterparts select Callers.
Select function, press cmd-shift-A, "Callers"
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"
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.
With xcode 4 you can now right click on references and select "jump to definition."

Textmate tab and de-tab selected block

Recently switched to Textmate on Mac for coding. On PC when ever I want to tab in or out a block of code I just highlight and press tab or shift+tab to move it in our out. It's very useful when you are adding an extra loop or conditional statement to a block of code to keep everything tidy and neatly indented.
On Textmate however when I try this it just replaces my selected text with a tab. So is there a way to do tab and de-tab lines of code in textmate?
Indent: Alt+Tab
Un-Indent: Shift+Alt+Tab
the hotkey is command-left bracket to move left and command-right bracket to move right
(the buttons next to 'p')
heres a link to more hotkeys and such
http://projects.serenity.de/textmate/tutorials/basics/
You can use Shift+Tab to decrease indent; You just need to make and assign a macro. You can reuse this technique to accomplish a great many things.
Enter some text, and intend them, this is mostly for feedback.
Click the Record Macro Button
Use ⇧+⌥+⇥ (aka; Shift + Option + Tab) to decrease the indentation.
Click the record button to stop recording the macro.
Use the Edit menu or ⌃+⌘+M to save your macro;
Saving will prompt you to create a new bundle*, or add your macro to an existing bundle.
Add a Key Equivalent by clicking in the field and pressing ⇧+⇥
Your bundle-macro should look like the one below, simply Save and you're done! TextMate will now decrease indent on ⇧+⇥
*: (as noted by u/PatrickT) Sadly the create new bundle functionality has not yet been implemented, and you must choose to add to an existing bundle. You can still create a bundle via Bundles -> Edit Bundles then Command + N.
As an alternative, you can change the keybindings, see Link
Here is what I did:
Install Link
Go to File -> Open -> User Key Bindings, this will create/edit ~/Libary/KeyBindings/DefaultKeyBinding.dict
Add a binding, for the action enter shiftRight: (indent) manually (this is a TextMate specific action and not in the pre-populated actions list)
Choose a shortcut, I used cmd+alt+right
Do the same for the action shiftLeft: (un-indent, I used cmd+alt+left)
Save and then restart TextMate
I used a shortcut with arrow keys as my right hand is already on the arrow keys when I am selecting multiple lines, so this is a good fit.
The reason why I did it was because I have a german keyboard and alt+tab/alt+shift+tab don't work for me since I am using Witch for app-switching using these exact shortcuts.
EDIT: cmd+alt+left/right don't work when you have multiple tabs open, as they are used for navigate to next or previous tab in TextMate... seems this cannot be changed or overridden (I tried Setting Shortcut Keys in Textmate). Looking for an alternative shortcut now.

Resources