Navigating in Xcode
– âŒ˜2 Symbol Navigator
– âŒ˜3 Find Navigator
– âŒ˜4 Issue Navigator
– âŒ˜5 Test Navigator
– âŒ˜6 Debug Navigator
– âŒ˜7 Breakpoint Navigator
– âŒ˜8 Log Navigator
And if you need the extra space and want to get rid of the navigator then use âŒ˜0 (command zero).
At the bottom of the navigation area there are the navigation filters. These are different for each tab and are very helpful. In the project navigator tab, the filters allow you to see the recently modified or recently edited files. Recently modified lets you focus on your SCM changes.
You can also enter some text and try to filter the name of the files if you know what youâ€™re looking for. However, better than using that filter is to use open quickly. The keyboard shortcut for that is:
â‡§âŒ˜ o Open quickly
This is very handy and very smart. Even if you donâ€™t remember the full name of the class or method youâ€™re searching for it can still help you find it.
I didnâ€™t even have to specify the full words (why write view controller when you can write just a few letters) and it still found what I was looking for.
And if you want to open the file and go to line 246 because you know thatâ€™s where that method is then you can just add :246 in the open quickly window and Xcode will do that for you. And if you want to skip to another line then just press
âŒ˜ L Go to line
and enter the line number.
Show line numbers
If you wish to show line numbers in Xcode 5 simply hold down the cmd and , buttons together and a window will pop up. In this window click Text Editing along the top options and then make sure the checkbox for Show: Line Numbers is selected.
Another very useful keyboard shortcut is the one that allows you to switch between the .h and .m file for a class.
âŒƒâŒ˜â‡¡ Jump to Next counterpart
And a very similar keyboard shortcut if you want to go back to the previous file you were looking at. Or forward again:
âŒƒâŒ˜â‡¢ Go forward
âŒƒâŒ˜â‡ Go back
When youâ€™re editing the code you might decide that an instance variableâ€™s name is not as suggestive as it should be or that there is a spelling mistake in it. You want to rename all instances of that variable, but only in a certain scope. Select one of the instances and then hit:
âŒƒâŒ˜E Edit all in scope
Youâ€™ll see that all the occurrences of that variable have boxes around it. Editing one will update all the others. This is very helpful for code refactoring and cleaning. Also very useful during refactoring is moving lines around. To do this you press:
âŒ¥âŒ˜[ Move line up
âŒ¥âŒ˜] Move line down
The indentation will be fixed as you move lines up or down, but if you still have some code thatâ€™s not properly indented then use this shortcut:
âŒƒI Re-indent code
If you want to Auto-Indent a block of code, check out this article: Auto-Indent Lines of code in Xcode.
If you need to comment things out just press:
âŒ˜/ Comment/uncomment line or selection
Apart from the standard editor Xcode also has an assistant editor and a version editor. To switch from one to another you use the following:
âŒ˜â†© Standard editor
âŒ¥âŒ˜â†© Assistant editor
âŒ¥â‡§âŒ˜â†© Version editor
The assistant editor is excellent for auxiliary content. It tracks the contents of the main editor. If you need to see the superclass for your class at the same time as youâ€™re editing the class just switch on the assistant editor. You can see counterparts, callers or test callers, includes and lots more. It is very powerful and I encourage you to use it. If you want to open a file in the assistant editor just hold the option key (âŒ¥) down:
âŒ¥âŒ˜, Open in assistant editor
Normally we set or remove breakpoints by clicking the margins of the document. You can also do this via keyboard shortcuts:
âŒ˜\ Add/remove breakpoint at current line
In the breakpoint navigator you can see all the existing breakpoints. To get to the navigator you press âŒ˜7
âŒ˜Y Activate or deactivate breakpoints
Very useful while debugging is the exception breakpoint. If your app is crashing just add an exception breakpoint and the program will stop at the line thatâ€™s causing the problem. You can do this by pressing the + at the bottom of the breakpoints navigator or from Xcodeâ€™s main menu by going to Debug-> Breakpoints -> Create exception breakpoint.
To run all the tests in your project use âŒ˜U . Or âŒƒâŒ˜U to test without building.
The test editor is your best friend when running your tests. You get to it by pressing âŒ˜5 From here you can run only one test by pressing the little play button that appears next to it, a whole test suite or all your tests.
You can also filter results so you can see only the failing tests:
If you want to debug the test then you can add a test failure breakpoint from the breakpoint navigator the same way you would add an exception breakpoint.
âŒ¥âŒ˜C Commit code
âŒƒâŒ¥âŒ˜X Update all
You can use the version navigator to check whatâ€™s changed in a file and whoâ€™s to blame.
âŒ¥â‡§âŒ˜â†© Show version editor
âŒ˜= Size to fit content
âŒ˜_ Add horizontal guide
âŒ˜| Add vertical guide
âŒ˜â‡ Rotate left
âŒ˜â‡¢ Rotate right
âŒƒâŒ˜Z Shake gesture
â‡§âŒ˜M Simulate memory warning
âŒ˜T Toggle slow animations