Brian Gesiak
Brian Gesiak

Reputation: 6958

In Xcode, is there a way to search for all lines where a specific method is called?

It's easy to jump to a symbol definition in Xcode--it's a ⌘-click away. But what about the opposite direction? That is, given the methods:

@interface MyObject : NSObject
- (void)myMethodWithParameter:(id)parameter
           someOtherParameter:(id)someOtherParameter;
- (void)myMethodWithParameter:(id)parameter
             anotherParameter:(id)anotherParameter;
@end

Is there a way to search a project or workspace for all lines that call the -[MyObject myMethodWithParameter:someOtherParameter:] method?

Note that I'm not asking for lines that include the text "myMethodWithParameter:", since that will turn up results for both methods. I only want results that call the first method, not the second.

Xcode uses libclang to perform symbol lookups, so presumably it knows which method each line is calling. So theoretically, this seems like it should be possible...

Upvotes: 2

Views: 132

Answers (2)

user2877496
user2877496

Reputation: 233

You can change the Find navigator from searching for text to search for regular expressions, then you can be as detailed as you like.

Searching for the regex "myMethodWithParameter.*some" would return all instance of the first and not the second

On a side not Bamsworld's answer is good too, I had often wondered what those other options were for in the assistant editor. TIL

Upvotes: 0

Bamsworld
Bamsworld

Reputation: 5680

What you are after is a list of 'callers' of a particular method that you select (whether it be in a .h or .m). Xcode's assistant editor can do this.

Start by opening the assistant editor in Xcode. You should have a split screen. In the left side you should have the header or main file that contains the method you want to find its callers for. Make sure to position the cursor over the method in question.

Next click on the root bread crumb above the right side in the toolbar above. The icon you're looking for is either a bow tie or a book. When clicked on a list should open up that you can scroll down until you see something like 'callers(3)' Hovering over it will expand out all the methods that call the method you selected in the left side. The number in the parenthesis is how many callers of the method there are in the project.

The assistant editor is really cool and it has a lot of useful features.

Upvotes: 1

Related Questions