example

24 Xcode Useful Tricks

Author: Mr. Paul Hudson | Website: Hacking with Swift

Ranjit

1) Generating class initialisers

We can create a Member-wise initialiser for class(is MoreUseful) Model or Struct Model using Refactor option.

Select Class name -> Refactor -> Generate Member-Wise Initialiser

2) Environment overrides

Where we used to see the View Debugging Hierarchy, besides we can figure out this option. So, with help of this, we can live rendering out the bigger font text and dark mode and light mode and grayscale and different testing possibility related to the environment. We can easily debug and see the live output.

Run the App -> Bottom of the Xcode -> You will find the Environment override option

3) Selecting blocks of code

This is simply selecting a starting brace and Xcode will select and tells us where it ends.

Select starting brace of any function and double tap it.

4) Checking your spelling

Xcode is very smart at checking your spelling is correct. It clears typo errors on your double-quotes. Like “Hello Wrold”.Here world spelling wrong. You can correct it by simply following the steps

Select Edit menu -> Format -> Spelling and Grammar -> Check Spelling While Typing

It can highlight the word error on the red colour underline. And you can simply right click and correct it or visualise the entire screen what and also the typos are presented.

NOTE: Even it gives you an error when you are following camelCase properly also.

Like: firstname => it should be firstName. Then you will easily catch an error.

5) Fixing all issues

You may find this protocol does not confirm all the functions or variables. By the time, Xcode will give a dotted red colour button. Where you tap on it, It will add needed functions or vars to the class. But what likewise if you are getting more errors. How to fix instantly all those.

Editor -> Fix all issues. Boom. It will fix the entire errors on adding the missing functions and vars.

6) Deleting Search Results

Usually when we go searching any file or text. It will list down the matches files. What if you are interested in them all. Just interested in some files. You can easily ignore the files which you don’t want tapping on backspace or delete option

Search any text on Xcode -> Select any of search result -> press backspace or delete option.

It will be removed from search results.

7) Resuming the SwiftUI Canvas

Sometimes the canvas will get stuck when you make some changes in your code. By the time you will be able to see the RESUME button on the right side of the screen. But easily you can do it with help of shortcuts.

Option + Command + P -> Resume SwiftUI Canvas

Option + Command + return -> Hide SwiftUI Canvas

8) Tiling the Simulator

This is like people who want to view the simulator and Xcode on one screen. So easily can do multitasking.

Two ways you can achieve this, by doing a full screening of the Xcode and drag the Simulator merge into your full-screen Xcode. So, automatically this can happen. Otherwise,

Select simulator -> Window -> Tile window to Right/Left of Screen

9) Expanding autocomplete

Xcode automatically gives you autocomplete on typing any code you like. But sometimes it will be a lengthier one as well. And in the tail of the function, you will see dot dot. So, here is the tip you can resize the autocompletion window by over drag it.

10) Quickly toggling breakpoints

Enable and delete breakpoints is heavier work when you do with your mouse or trackpad. But using shortcut is much simpler.

Command + BackSlash {Toggle function to enable and disable}

11) Randomising test order

Usually, we use to write a test function in an ordered way. Because mostly the second test function may be required to run the first function. But what if I want to run these in random order. Here is the tip:

Product -> Test -> Info -> Options -> (check)Randomise execution order

This will run the test cases in random order. So it will give more confidence on not depending on any order or function.

12) Filtering the jump bar

Usually, we use to see the list of functions on vars when clicking the method list. But if you have a big list, you cannot simply scroll and see. In Xcode wherever you see the list, the hidden feature is SEARCH BAR is there. You start simply typing it and it immediately giving you the result.

For example: Xcode Target and Schemes

13) Generating an Interface file

When you want to see the Class file interface what and major functionalities are written. Unless otherwise, you have to go through the entire class then only you will come to know. How to see protocol kind of methods in a class. Xcode will help you easily using the shortcut.

Control + Command + UpArrow — To See Interface File

Control + Command + DownArrow — To See Interface and Implementation both.

14) Adding comments quickly

What if you want to add documentation quickly to your function. Here is the tip:

Option + Command + FrontSlash(/)

This will add function description along with parameters

15) Finding files faster

There are two ways you can find a file from your project particular group or all over the project files.

From a particular filegroup, you can RIGHT click the group and sort by name.

From Project files at the bottom of the search bar start typing the name of the file. You will find it easily.

16) Seeing source changes inline

Xcode beautifully handles the source code changes inside the editor.

Preferences -> Source Control Tab -> Check Show Source Control changes.

Once it is checked, then you simply make the changes you will be able to see BLUE BAR where you see the breakPoint of the code line. Even you can click on the BLUE BAR, and see the change of the code. If you want you can withdraw it.

17) Finding code in the minimap

Usually, this minimap helps to easily jump into a particular portion on a longer swift file. Even you can mouseover in the minimap you will get to know the method name.

Editor -> Minimap

Even you can click the COMMAND key to list down all the method names in a list

18) Re-Run your last test

What if you want to run your last test. Particularly run the last one. Sometimes you just want to tweak something to see the last one. Here is the command tip:

Control + Option + Command + g

19) Remapping unhelpful keys

Unnecessary shortcuts may collide with the handy shortcuts. Like, when you press COMMAND + SHIFT + O -> this will open the file quickly. But you may press COMMAND + SHIFT + P also, you can avoid print and page setup shortcuts from keybindings.

Preferences -> Key Bindings -> Page setup

Search and delete the shortcut.

Even refreshing the SwiftUI canvas you may use COMMAND + P. Quickly you can do your job with help of changing the shortcuts.

20) Upgrading your searches

You can search a word using Find, Text, Containing but when you tap on the Search icon(Magnifying icon) you will be able to get search history and a lot.

21) Reindenting code

Copying and pasting code looks vague. Here is a tip:

Select the code -> Control + i

22) Testing in-app purchases

You can test in-app purchase inside your Xcode project.

Command + n -> Search Storekit configuration file -> Save

Then select based on the scheme of your in-app purchase and click Product menu -> RUN -> Options Tab -> StoreKit Configuration -> set new store kit configuration file. BOOM That’s it.

Rather than going to AppStore in-App purchase, you can easily test out with this setup.

23) Exploring build options

Enable BitCode. What does it do? Select Enable Bitcode option and OPTION + DOUBLE CLICK. You will get a summary window of What is the advantage of enabling the bitcode.

24) Pinning previews

When you want to change custom cell text view font and want to see the whole table view reflection of this change. You can easily pin the parent view using the bottom of the canvas.

If you want watch these tips in Youtube video please go though this link: https://www.youtube.com/watch?v=8kiR_QsQNPc

No responses yet

Write a response