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."
Related
The "Update Frames" calls are often grayed-out in Xcode
the only way I know to have it update frames to match your constraints, is, tediously select your highest-level view and than (sometimes) you can fish in the menu bar for "Selected Views"->"Update Frames". Further, "All Views"->"Update Frames" would appear to often simply not work or work in a way I can't understand.
Surely there's just a keystroke or button which updates all frames straight away to match any newly-entered constraints (such as those made using control-drag).
Note .. for 2016 you can use this very handy button, which at least brings up the same sub-menu as you can find by searching in the menu bar menu.
However it would seem (see my comments w/ ZaBlanc below) that there is perhaps actually an Xcode bug, and you CAN NOT assign a keystroke to the "All Views" items. (The ones you usually use.)
Even worse .. in Xcode 8 ...
they seem to have removed the 'update frames' option ... WTH
It's easy. Go to Preferences -> Key Bindings. Type "Update Frames" on the top. You'll see two appear. You'll want the bottom one (it will be the one without a keyboard shortcut assigned.)
Assign it to ⌘= or anything else you like.
Life changed.
Just for anyone reading, with Xcode 8.3. The popup menu command no longer exists. The menu bar command Editor -> Update Frames does work. However there's a bug, the default key binding on that does not work. If you add a custom key combo, that custom key combo does work.
AFAIK, there is no keystroke for update all frames, but here's a key tip:
If you have a misplaced views, press the yellow arrow in the document outline (the views tree to the left of canvas), press yellow triangle on any view in the list, then select update frames and check Apply to all views in container - this will update all misplaced views in the selected view controller
Additionally, you probably already know:
You can add a new constraint with Add New Constraints button in canvas bottom right and select "Update frames" option.
You can select any view by mouse-click and holding Option+Shift keys - this will show you the list of all the views, that intersects with mouse pointer. After that you can select update frames menu item on a selected misplaced view.
The same as you, I thought that it's very annoying to fix the misplaced views manually by selecting them and choose that boring option from Xcode menu. After trying hard to shorten the time to fix the layout issues, I had to admit that there is no way to call the function "Update Frames" from command line. So I ended up doing this way:
Open Xcode warnings & error inspector window
Filter all layout warnings by using the keyword "frame for"
Click on warnings to quickly locate to the misplaced views then press Command + Option + =
That's the fastest way I know. Please try it out!
You could also find more details HERE
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.
I'm using Xcode 4.3 for Objective-C development.
One feature that I like in other text editors (I know Xcode is an IDE), is jumping to a method definition within the same code file.
For example if I'm in #implementation of Calculator and calculator has 10 methods, I will like a way to jump between them.
If I press command+L I can jump to a specific line number, is there a way to jump in a similar way but to a method definition? e.g. instead of typing the line number to type only the beginning of the method name.
Can I open somehow a dialog box, type the beginning of a method signature and see instantly the search results and If I pick one method it will get me to it?
Is there a way to jump from a method to the next one?
I think this is what you're looking for:
Type ctrl-6 to activate the "Show Document Items" in the "Jump Bar". Then start typing part of the method you are looking for to narrow the results.
Example:
To jump straight to - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Type ctrl-6, type "cellFor", arrow down so the method is highlighted, and press Enter. The Editor will jump right to that method.
Incidentally, you can use ctrl-1, ctrl-2, ctrl-3, etc. to access the different sections of the "Jump Bar".
If I understand you correctly, try Command-Shift-O. It also doubles as a file finder.
Perhaps I'm not understanding what you need, but it seems like you have a couple of options.
Control+Command+J should take you to a definition.
Control+Command+Up/Control+Command+Down will toggle between .h/.m files.
While in the .m file, I use the dropdown for the methods often.
If you want to press a command key sequence like Command + Option + ↓ to jump to the next method, or Command + Option + ↑ to jump to the previous method, there is no such animal in Xcode. Prior macOS development tools had such a capability, but Xcode is seriously lacking in the basics...
The fastest jump back and forth in methods in a source file is to perform a Command + F (Find) on [\-\+][ \t]*\( as a regular expression. Then you can Command + G (Find Next) to go to the next method or Command + Shift + G (Find Previous) to go to the prior method.
If you are disciplined in your method definitions, you might be able to search for - ( or + ( as a normal text string instead... a tad faster.
If this is a serious itch to scratch, maybe it is worth creating an Xcode plugin (as silly as this sounds for such a basic feature)... and post a link here for the rest of us ;-)
Select a symbol (could be a method, but doesn't have to be) and right-click (or control-click). The contextual menu that pops up has a "Jump to definition" command. Control-command-J is a shortcut for that.
If the thing you're looking for isn't visible, you can use the Search Navigator (Command-3) to search through the code.
Depending on what you're looking for, you may also find the Quick Help feature in the Utilities panel helpful. If you select a symbol, Quick Help will give you at least some basic information about that symbol. For symbols in the iOS or MacOS X API's, you get quite a bit of help. If you've selected your own symbol, it'll tell you where that symbol is declared, and you can click on the file name to jump to the declaration.
I don't think there's a command to jump to the next method (where in the method would you want to jump to?). If you have a need for that sort of thing, you might find Xcode's code folding features useful. You can fold an entire method or just some of the blocks within the method. Very helpful for getting the lay of the land when you're looking at a large file for the first time.
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
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