Find Callers of methods or variables in Xcode

⋅ 1 min read ⋅ Xcode Debugging

Table of Contents

What is Caller

Callers or Call Hierarchy shows you all the places (files and line of codes) where a method, function, or variable is used.

You can easily support sarunw.com by checking out this sponsor.

Sponsor sarunw.com and reach thousands of iOS developers.

How to Find Caller of Call Hierarchy in Xcode

There are several ways to find callers in Xcode. I will give you three ways to do it.

  1. Command + Click
  2. Related Items
  3. Search Interface

Command + Click

You can find callers via a context menu.

To do that.

  1. Command + Click (or Command + Control + Click) on a method, function, or variable name will open up the actions menu that you can do on that object.
Command + Click
Command + Click
  1. Select "Callers", and Xcode will show all the places that the variable is used.
Callers
Callers

You can also find callers in the Related Items.

Navigation to Related Items.
Navigation to Related Items.

To find the callers.

  1. Move the cursor to a method or a variable that you want to find the callers.
  2. Then Click on the "Navigation to Related Items" button or
    Press ⌃ – control + 1 or
    Select View menu > Editor > Show Related Items.
  3. All callers will show under the Callers menu item.
Navigation to Related Items button.
Navigation to Related Items button.

Search Interface

You can also find the callers via the search interface.

To do that.

  1. Move the cursor to a method or a variable that you want to find the callers.
  2. Press ⌃ – control + ⇧ - shift + ⌘ - command + H.
  3. All the places that the method or variable is called will show up in the Find Navigator panel.
Find Navigator.
Find Navigator.

You can easily support sarunw.com by checking out this sponsor.

Sponsor sarunw.com and reach thousands of iOS developers.

What is the benefit of Call Hierarchy

Knowing the number of callers gives you a rough idea of the dependency you have around a method or variable, which is useful when you are about to make changes.

An ability to show all the places that call a method is also valuable when debugging. You can ensure all the call sites are fixed along with the broken ones.


Read more article about Xcode, Debugging, or see all available topic

Enjoy the read?

If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.

Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.

If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.

Become a patron Buy me a coffee Tweet Share
Previous
What is contentInset in a scroll view

Learn the importance of content inset.

Next
Back deploy Swift Function

Does this mean we can finally enjoy the new SwiftUI feature while still supporting old versions of iOS? Let's find out.

← Home