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

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

Related

How to make xCode "act" as the most normal editors?

I wonder, why doesn't xCode "act" as a normal editor? For example, when I press Ctrl+X, I'd like the current line to be copied-cut. When I press Shift+Tab I'd like the current selection to be shifted to the left, etc. That's the stuff most editors do by default.
How to make it do that?
Take a look at Preferences -> Key Bindings. Here you get a list of actions and their keyboard shortcuts - and you can change those keyboard shortcuts!
It's quite amazing how many actions there are, including a great number of familiar Emacs actions such as mark and yank. Many of them have no corresponding menu item; many of them have no keyboard shortcut by default. Some of them may be the things you are looking for, and all you need to do is change the shortcut if you don't like it. It is very possible that you'll find at least some bindings that you can use to make Xcode behave in a more familiar way.

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.

Is there a way to jump to a specific method in Xcode?

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.

Xcode keyboard shortcut: jump to test file?

Is there an Xcode keyboard shortcut to jump from MyObject.m to MyObjectTests.m, and vice versa? If so, what is it?
I haven't found a way to do this. Feature request material I think.
At the bottom of "Project Navigator" you can type your filename in the search area to dynamically search for files you would be interested in. They will be filtered as you type.
If you always place your ClassTests next to its Class, you can use Control + 5 followed by Up/Down and Return. Three keystrokes. Not ideal but works.
Command + Shift + O works fairly well. It is an open quickly command, so you can type in the name of the file and get a list of:
MyObject.m
MyObject.h
MyObjectTests.m
It remembers what you typed last too, so next time you Command + Shift + O (in the same XCode instance) you can now down arrow twice and return to get from source to test file. Works in XCode 6.3 / 6.4; I am not sure about other versions.
If you already know the name of the test file where the relevant tests are located, then of course the above answers work well. But if you don't know where the tests are (such as when you inherited an old code base or it's been more than 2 days since you wrote it), there are two ways to do it.
The keyboard shortcut ctrl-cmd-up will take you to the "generated interface" (a leftover from the objc days) for that file, but pressing it a second time will take you to the associated test file
Use the assistant editor, which can be turned on either through the little menu in the top right corner, or through the keyboard shortcut ctrl-opt-cmd-enter. This will usually show the test file for an associated file (or vice versa if you're looking a test file!)

Xcode find caller functions

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

Resources