源地址:http://holko.pl/2016/04/26/xcode-search/
#1: Patterns
Searching for text in Xcode is quite easy. Type Command-Shift-F and off you go. That's not enough, though, when we want to perform a more advanced search. If, say, we wanted to search for strings containing URLs we'd end up with a pretty complicated regular expression. This is so common case, that Apple decided to help us by introducing the ability to search for wildcard patterns.
To do that, we start by clicking on the loupe button with the disclosure indicator next to it:
Then, we are presented with the list of the available patterns:
Clicking on a pattern inserts it into the search field. Just like that we got a list of strings representing URLs:
Patterns are a good middle ground between simple text searches and regular expression.
#2: Definitions
Xcode also provides search options leveraging its understanding of the code structure. Let's say, we want to find all singletons that crept into our project. We'll use a heuristic here by assuming that all of them have methods or properties named shared*
.
If we simply search for shared
we get a lot of results:
To narrow the results we have to click on Text (which doesn't look like a clickable element!) and choose Definitions instead:
And we're done!
With Definitions filter we can also search for a class, struct, and enum names; enum cases and more.
#3: Search Scopes
Choosing a project or a group that we want to search in is often enough:
Let's imagine that we work in a mixed Objective-C/Swift codebase. (It wasn't that hard to imagine, right?