Xcode Search: the Hidden Gems

源地址: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:

Search Options

Then, we are presented with the list of the available patterns:

List of Available Patterns

Clicking on a pattern inserts it into the search field. Just like that we got a list of strings representing URLs:

Strings Representing URLs (in  Eidolon, thanks for OS Artsy!)

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:

Default Search Results

To narrow the results we have to click on Text (which doesn't look like a clickable element!) and choose Definitions instead:

Definitions Option

And we're done!

Search Results Narrowed to Definitions

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:

Scopes Menu

Let's imagine that we work in a mixed Objective-C/Swift codebase. (It wasn't that hard to imagine, right?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值