在 Xcode 中对所有 .xib 文件进行文本搜索?
这似乎是一项基本任务,但我很困惑。
在 Xcode 中,如何对项目中的所有 .xib 文件(的 XML 内容)执行文本搜索?
例如,我们所有的 .xib 文件在第二行都包含此字符串:com.apple.InterfaceBuilder3.CocoaTouch.XIB
。所以我认为在所有项目文件中搜索该字符串将返回所有 .xib 文件,但 Xcode 坚持“0 次出现”。我已经仔细检查过项目查找选项看起来是否正确。
我一定错过了一些明显的东西。 (或者 Xcode 以某种方式硬编码以跳过 .xib 文件。)
我试图找到引用特定类的所有 .xib 文件(文本搜索似乎是最直接的方法)。
谢谢!
This seems like such a basic task, but I'm stumped.
How, in Xcode, do you execute a textual search though (the XML contents of) all the .xib files in a project?
For example, all of our .xib files contain this string on the second line: com.apple.InterfaceBuilder3.CocoaTouch.XIB
. So I'd think that searching all project files for that string would return all .xib files, but Xcode insists "0 occurrences". I've double checked that the Project Find Options look correct.
I must be missing something obvious. (Or Xcode is somehow hard-coded to skip .xib files.)
I'm trying to find all the .xib files that reference a particular class (and a text search seems like the most direct way).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
在sublime text中打开项目文件夹并搜索所有文件,非常简单方便。
Open the project folder in sublime text and search in all files, very easy and convenient.
grep -i -r --include=*.xib "TextToFindHere" /PathToSearchHere
响应:未找到匹配项:--include=*.xib
工作正常。
grep -i -r --include=*.xib "TextToFindHere" /PathToSearchHere
response: no matches found: --include=*.xib
this work fine.
如果您使用作为服务,这将有效......
This works if you use as service....
我遇到了同样的问题,我使用一些控制台命令解决了它。
在 Mac 上打开终端
运行
grep -i -r --include=*.xib "searchtext" /your/project/path
命令它将在路径“/your/project/path”中搜索并打印完整路径使用“searchtext”的所有文件 xib。
I had the same problem and I resolved it using some console commands.
Open Terminal on your Mac
run
grep -i -r --include=*.xib "searchtext" /your/project/path
commandIt will search in the path "/your/project/path" and will print the complete path of all files xib that use the "searchtext".
在当前的 Xcode 版本 (13) 中,我无法让它用于搜索纯文本,例如 Storyboard 和 xib 文件中的
stackView
。但可以搜索 UI 元素的
id
或userLabel
,就像如果您提供 id
kBd,您就会找到这个
。stackView
- Xcode 查找字段中的 Vg-03c因此,结合这个问题中有关
find
和Terminal
的几个答案,我创建了一个脚本,返回所有
id
故事板和 xib 文件中包含我正在搜索的文本的元素。您可以从项目的根文件夹调用该脚本。
结果是所有
id
与正则表达式的|
(或条件)的组合。然后复制此结果,并在
Xcode
中,Find
选择Regular Expresion
,然后粘贴脚本的结果字符串。然后您将得到如下结果:
In the current Xcode version (13), I could not make it work for searching plain text, like
stackView
in storyboard and xib files.But it is possible to search for the UI element's
id
oruserLabel
, likeyou will find this
stackView
if you provide idkBd-Vg-03c
in Xcode find field.So, combining a couple of the answers regarding
find
andTerminal
in this question, I created a script that returnsall
id
s of the elements in storyboard and xib files that contain the text that I am searching for.You call the script from the project's root folder.
The result is the combination of all
id
s with regex's|
(or condition).You then copy this result and in
Xcode
,Find
chooseRegular Expresion
and then paste the script's result string.You will then get results like this:
我所做的是在终端中运行 grep:
Xcode 似乎没有搜索 xib 文件的选项,并且我尝试让 Spotlight 查看它们但没有成功。
What I do is run grep in terminal:
Xcode doesn't seem to have an option to search xib files and my attempts to get Spotlight to look at them have been unsuccessful.
这是我的方便命令,它永远不会让我失望。从终端中的项目目录运行它。
寻找 。 -name "*.xib" -exec grep "要查找的文本" {} \; -打印
Here is my handy command that never fails me. Run it from the project directory in Terminal.
find . -name "*.xib" -exec grep "text to look for" {} \; -print
我意识到这已经很老了,但我想建议那些碰巧也在计算机上编写其他语言并选择使用 Sublime Text 2(这非常棒),只需在 Sublime 中打开 iOS 项目的文件夹并使用查找所有功能即可。非常快,非常可靠。
这就是我从一个较大的项目中删除未使用的图像资源时所做的事情。
~ 快乐编码 =]
I realize this is quite old, but I'd like to suggest to those of you who happen to also code other languages on your computer and choose to use Sublime Text 2 (which is wonderful) to do so, just open your iOS project's folder in Sublime and use the find all feature. Very fast, very reliable.
This was what I did to remove unused image resources from one of my larger projects.
~ Happy Coding =]
我可能很愚蠢,但是使用聚光灯对我来说非常有用。
I may be daft, but using spotlight works great for me on this one.
您可以通过定义新范围来更改 Xcode 中的搜索范围。转到搜索面板,搜索栏下方有一个带有三个点的图标(可能默认为“在工作区中”)。单击该按钮,然后在“搜索范围”下单击“新范围”。将其定义为 "Name" / "ends with" / ".xib" 。
You can just change the search scope in Xcode by defining a new scope. Go to the search panel and below the search bar there is an icon that has three dots (probably defaulted to "In Workspace"). Click that and under SEARCH SCOPES, click "New Scope". Define it to be "Name" / "ends with" / ".xib" .
您可以在 bash 配置文件中使用此函数:
然后只需在终端中调用“grep_xib TEXT_TO_FIND”即可。更容易了。
要在 Mac 上创建 .bash_profile,请按照以下步骤操作:
U may use this function in your bash profile:
Then just call in terminal "grep_xib TEXT_TO_FIND". It's easier.
To create a .bash_profile on your mac follow this steps: