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.
Related
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 trying to get into Accessorizer, but every time I am trying it, I run into the same problem. I select some code (for example, multiple #property statements), hit cmd-c and move my cursor to the place I want the generated code to be.
I now use Accessorizer's menu, select Implementation and my copied properties are pasted in, instead of #synthesize statements. As far as I can see, I followed the setup instructions precisely. I don't like the difficult to use shortcuts, so I would like to use the system menu, at least for now.
Ah, so you need to invoke the Accessorizer text service by pressing shift-alt-cmd-0 instead of cmd-c. That sends the text to Accessorizer. Only after you've done this, you can use the Action Menu / press shift-ctrl-cmd-0.
XCode is a little weak in the way that it obliges you to format code, and the restrictions it places on you. I'm thinking of things such as select a block of code and use tab to reposition the whole block, which is very useful for cleaning up indenting, amongst other things.
I realise that I can use an external editor (such as Sublime Text 2, which is superb and my daily editor) to edit code, but I'm wondering if there are any plugins or tools which exist out there which integrate into xcode to improve this development experience.
What kind of extensions exist for xcode, or if there aren't any, are there any lesser-known features which assist in improving this?
It's hard to give you an answer, as we don't know what features you use elsewhere that you think are missing in Xcode. For example, you can move a block of code in or out by pressing Cmd-{ or Cmd-}. Or you can "fix" the indenting by using ctrl-i as jrturton pointed out above. All of the emacs keybindings work. In fact, you should look over the key bindings in the prefs to see what other things are possible. Some of my favorites are:
1) Select a word and hit Cmd-E to make it the search term. Then Cmd-G to find the next instance.
2) F6 to step over in the debugger, F7 to step in and F8 to step out
3) As much as I hate command lines, gdb has a number of useful commands for calling methods while stopped at a breakpoint. You can call any function or C++ or Objective-C method using the call command. (Type help call at the gdb prompt to learn more.)
4) If your index is up-to-date, you should be able to Cmd-click on a symbol to go to it's definition, or option-Click to see its documentation.
Are those the sorts of things you're looking for? If not, please give examples of what you want. As far as I know there is no plug-in mechanism in Xcode 4, so no extensions exist.
Though the first answer is a great one (learned a lot from it), I wanted to add a little hint that helps me a lot when pasting codesnippets. A lot of times xCode copies indentation in a way I don't like and then I have to reindent the whole snippet.
What I started to do is jump to the first char in line (ctrl + a | cmd + ArrowLeft) and either paste the code immediatly, or indent by one or two before pasting, dependend if I'm in a function, loop etc.
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
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!)