As iOS Developer you must be spending 8–9 hours of the day using Xcode. It is really important that you know the IDE to get most out of it and get more efficient with coding.
Refresh Canvas and close/open canvas
While using SwiftUI one of things you interact most is SwiftUI previewer and we see the Resume button on the previewer and have to click it to so many times.
Well there is a keyboard shortcut that can make your life easier. By default it is set to Option + Command + P but you can reconfigure it your liking. e.g. I have set it to Command + P
and to do this I had to remove the shortcut for Print. Let’s be very clear we do not do Print command from Xcode every day :), So I choose the nearest key to the default one.
Another good shortcut to know if Opening and closing the Canvas, May be there are times where you want to just focus on code and get some more real estate to work with and just want to close the canvas and then once done you want to reopen it again. You can use Option + Command + return to toggle the canvas visibility. Again you can use Xcode keybinding to reconfigure it to your liking.
Open Quickly
If you are working on large project and working on few files then you must know this feature of Xcode. Open quickly let’s you open files with you know the name of the file. Press Command + Shift + O to open it and then just start trying the name and you will see the list
A companion option to this one is show only recent files toggle in the project navigator. When enabled it will only show the files you have recently interact with.
Rename refactoring
Naming the variables and functions especially in swift era is very hard and sometime names are too long, if you are not happy with the naming you want to change the name, this is where rename refactoring comes handy. You can right click on name you want change and choose Refactor -> Rename and rename the field.
As showing in image you will get an overview of all the references which will be updated the you rename the field. Also, if you look closely on the top there is more information about if any files will be renamed, comments will be updated and other information. Play with rename feature and see what all the options you see.
Again, you can configure a keyboard shortcut for your convenience just got to keybinding and filter for rename
In file rename Control + Option + R and rename from refactoring
A companion feature is rename in same file is edit all in scope. You can press Control + Command + E which is default key binding. It will rename the variable in scope.
Themes is really important if you want to customise the view of the editor as per your liking. By default Xcode provide some themes, which you can view by going to Editor -> Theme
Select different themes a see which is closest to your liking and then you can edit that theme by choosing Edit Themes
Invisibles
If you want to see invisible characters in your editor you can turn them on using Editor -> Invisibles
I have them turned off usually, but if you have a file that you want to read with all the hidden characters and see what is in there this might be a handy option for you.
Well code is not behaving the way you were thinking and now we need to debug. You put a breakpoint in the code. there are couple of ways to do it. One is by clicking the gutter on the left side of the line it will add a breakpoint,
If you are someone does not like to touch the mouse while coding you can press Command + \ to toggle the breakpoint on the line where your cursor is. you can use this keyboard shortcut to remove the breakpoint as well, other way is to click drag and drop the breakpoint on the editor to remove it. Because you just click it on again it will just disable the breakpoint on remove it.
If you want to enable or disable all the breakpoints you can click Breakpoint icon in the system bar at the bottom.
Files in Navigator
You are editing a file and now want to select that file in the Navigator. You can press Command + Shift + J to got to the file in Navigator.
Now you have selected a different file in the navigator and want to go to Editor for the selected file. You would thing press return will do it but no that will rename the file. You want to press Command + J to move focus to the editor.
Originally published at https://www.codewithkarma.com.