Leonardo Maia Pugliese
Holy Swift

Holy Swift

Check Find Navigator Search History in Xcode

Check Find Navigator Search History in Xcode

Xcode tips and tricks!

Leonardo Maia Pugliese's photo
Leonardo Maia Pugliese
·Mar 2, 2022·

4 min read

Subscribe to my newsletter and never miss my upcoming articles

Hallo jongens en meisjes, Leo hier.

Today I'll show something that I discovered recently in Xcode. I always wondered 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

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.

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

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.

Screenshot 2022-03-01 at 08.04.02.png

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:

Screenshot 2022-03-01 at 08.06.35.png

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

In the Find Navigator I can see the results:

Screenshot 2022-03-01 at 08.19.10.png

It didn't find anything. But why? Because by default the shortcut I use always search for a Symbol Reference and that means, it's not something like a class, struct, enum, 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:

Screenshot 2022-03-01 at 08.29.30.png

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:

Screenshot 2022-03-01 at 08.35.53.png

I was so happy that I found this. I can't count the times I wanted to have the history and I just forgot what I've searched for minutes ago.

Extra Xcode tip - Function's Callees and Callers

Screenshot 2022-03-02 at 08.05.46.png

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:

Screenshot 2022-03-02 at 07.56.12.png

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

Screenshot 2022-03-02 at 07.59.56.png

Observe the callees and the callers of the testName function:

Screenshot 2022-03-02 at 08.07.12.png

Screenshot 2022-03-02 at 08.07.30.png

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

Today we went through two features of our beloved Xcode, the Find navigator search history 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 it as I enjoyed writing this article. If you want to support this blog you can Buy Me a Coffee or just leave a comment saying hello. You can also sponsor posts and I'm open to writing freelancing! Just reach me in LinkedIn or Twitter for details.

Thanks for the reading and... That's all folks.

credits: image

Did you find this article valuable?

Support Leonardo Maia Pugliese by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this