Hallo jongens en meisjes, Leo hier. Today we will discuss Navigator Search History in Xcode and how you can use it to boost your productivity.

I’ll show something that I discovered recently in Xcode. I always wondered if that should be some type of “search history” on Xcode. Would be awesome to not have to guess what was my last search every time I need to remake older searches.

No more talking, let’s go! But first… The painting!

 

The Painting of The Day

The Sermon of Piotr Skarga or Skarga’s Sermon (Polish: Kazanie Skargi) is a large oil painting by Jan Matejko, finished in 1864, now in the National Museum, Warsaw in Poland. Jan Alojzy Matejko also known as Jan Mateyko born 1838 and died 1893. He was a Polish painter known for paintings of notable historical Polish political and military events.

It depicts a sermon on political matters by the Jesuit priest Piotr Skarga, a chief figure of the Counter-Reformation in Poland, where he rebukes the Polish elite for neglecting the national interest.

This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer!

Religion, based on Latin religare ‘to bind’. I chose this painting because we will talk about searching, in our case is a historic String search and the painting is searching for God’s guidance.

 

The Problem – Navigator Search History in Xcode

> I want to check all my previous searches in the Xcode Find Navigator.

Let’s talk about the importance of shortcuts in a life of a developer, I may be biased because I’m a big fan of IDE shortcuts. I love how easy is to navigate throughout your code if you know some shortcuts.

One of the most used shortcuts for me is the Find and Replace in Workspace.

Navigator Search History in Xcode example image 1

It is really simple to use.

 

1. First you need to highlight whatever thing that you want to search in your workspace. It can be a property, a type, a method, a protocol, etc. You can search for anything. For example, let’s search for the friendsDataFrame from the previous post:

Navigator Search History in Xcode example image 2

 

2. With the friendsDataFrame highlighted you can press command + option + shift + F.

In the Find Navigator I can see the results:

Navigator Search History in Xcode example image 3

It didn’t find anything. But why? Because by default the shortcut I use always searches for a *Symbol Reference* and that means, it’s not something like a class, struct, enum, or actor. It is a variable called friendsDataFrame, but it is also searched without the Reference Symbol filter that returns 14 matches.

If you click that you will see:

Navigator Search History in Xcode example image 5

This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer!

Now imagine that you are using the find navigator all day long. And you want to search again that you search a few seconds ago but you don’t quite remember exactly how was the name exactly.

I found that you just need to click on the magnifying glass on the left side and it shows your recent search history for you:

history of searches in Xcode image to check all your code searches in Xcode

I was so happy that I found this. Could not count the times I wanted to have the history and I just forgot what I searched for minutes ago.

 

Extra Xcode tip – Function’s Callees and Callers

Navigator Search History in Xcode example image 5

Imagine that you have any struct:

struct Human: Codable {
    let name: String
    
    func testName() -> String { name }
    
    func showNumber() -> Void {
        print(1)
    }
}

And you want to see where its functions are called throughout the codebase.

To achieve that you can use the Related Items section. The shortcut to it is control+1 or for the mac heavy users ^+1. If you press that with the pointer inside the function it will show how many times that function is called and by who.

To use that you need to follow these steps:

1. Highlighting the name property in the testName function:

property name highlighting for tutorial in searches on Xcode

2. Press control+1 ( or ^+1 ) to show the Related Items menu. Alternatively, you can click on the symbol to open the menu:

hidden Xcode feature called location related items

Observe the callees and the callers of the testName function:

final image 1 callers from function in Swift and Xcode example

final image 2 callers from function in Swift and Xcode example

It is really interesting to see that even we are not explicitly calling a function, behind the scenes it is calling the getter function for the name property.

And that is it for today!

 

Summary – Navigator Search History in Xcode

Today we went through two features of our beloved Xcode, the Find navigator search history in Xcode and the Reference Menu, and how that can be useful for you in your day-to-day development.

That’s all my people, I hope you liked reading this article as much as I enjoyed writing it. If you want to support this blog you can Buy Me a Coffee or leave a comment saying hello. You can also sponsor posts and I’m open to freelance writing! You can reach me on LinkedIn or Twitter and send me an e-mail through the contact page.

Thanks for reading and… That’s all folks.

Credits:

title image