通过 Xcode 中的所有 .xib 文件进行文本搜索?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3963378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:51:11  来源:igfitidea点击:

Text search though all .xib files in Xcode?

xcodefull-text-searchxib

提问by Jon-Eric

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?

在 Xcode 中,您如何执行文本搜索(XML 内容)项目中的所有 .xib 文件?

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.

例如,我们所有的 .xib 文件在第二行都包含这个字符串:com.apple.InterfaceBuilder3.CocoaTouch.XIB. 所以我认为搜索该字符串的所有项目文件将返回所有 .xib 文件,但 Xcode 坚持“0 次出现”。我已经仔细检查了项目查找选项是否正确。

I must be missing something obvious. (Or Xcode is somehow hard-coded to skip .xib files.)

我一定遗漏了一些明显的东西。(或者 Xcode 以某种方式硬编码以跳过 .xib 文件。)

I'm trying to find all the .xib files that reference a particular class (and a text search seems like the most direct way).

我试图找到所有引用特定类的 .xib 文件(文本搜索似乎是最直接的方式)。

Thanks!

谢谢!

回答by

What I do is run grep in terminal:

我所做的是在终端中运行 grep :

grep -i -r --include=*.xib "TextToFindHere" /PathToSearchHere

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.

Xcode 似乎没有搜索 xib 文件的选项,我试图让 Spotlight 查看它们的尝试没有成功。

回答by Moonwalker

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

找 。-name "*.xib" -exec grep "要查找的文本" {} \; -打印

回答by Ryan Crews

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.

我意识到这已经很老了,但我想建议那些碰巧也在您的计算机上编写其他语言并选择使用Sublime Text 2(这很棒)来这样做的人,只需打开您的 iOS 项目的文件夹在 Sublime 中并使用 find all 功能。非常快,非常可靠。

This was what I did to remove unused image resources from one of my larger projects.

这就是我从我的一个较大项目中删除未使用的图像资源所做的工作。

~ Happy Coding =]

~快乐编码=]

回答by Andrew Bennett

I may be daft, but using spotlight works great for me on this one.

我可能很愚蠢,但在这一点上使用聚光灯对我来说非常有用。

回答by Ted

U may use this function in your bash profile:

你可以在你的 bash 配置文件中使用这个函数:

function grep_xib {
    grep -i -r --include=*.xib "" .
}

Then just call in terminal "grep_xib TEXT_TO_FIND". It's easier.

然后只需在终端“grep_xib TEXT_TO_FIND”中调用。这更容易。

To create a .bash_profile on your mac follow this steps:

要在您的 Mac 上创建 .bash_profile,请按照以下步骤操作:

  • Start up Terminal
  • Type "cd ~/" to go to your home folder
  • Type "touch .bash_profile" to create your new file.
  • Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to open it in TextEdit.
  • Type ". .bash_profile" to reload .bash_profile and update any functions you add.
  • 启动终端
  • 输入“cd ~/”转到您的主文件夹
  • 输入“touch .bash_profile”来创建你的新文件。
  • 使用您最喜欢的编辑器编辑 .bash_profile(或者您可以输入“open -e .bash_profile”在 TextEdit 中打开它。
  • 键入“. .bash_profile”以重新加载 .bash_profile 并更新您添加的任何功能。

回答by Sarah Dygert

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" .

您可以通过定义新范围来更改 Xcode 中的搜索范围。转到搜索面板,在搜索栏下方有一个带有三个点的图标(可能默认为“在工作区”)。单击它,然后在搜索范围下,单击“新范围”。将其定义为 "Name" / "ends with" / ".xib" 。

回答by weiminghuaa

grep -i -r --include=*.xib "TextToFindHere" /PathToSearchHere

grep -i -r --include=*.xib "TextToFindHere" /PathToSearchHere

response: no matches found: --include=*.xib

响应:未找到匹配项:--include=*.xib

cd /PathToSearchHere
grep "TextToFindHere" ./ -r | grep ".xib"

this work fine.

这工作很好。

回答by Taha Selim Bebek

Open the project folder in sublime text and search in all files, very easy and convenient.

在sublime text中打开项目文件夹,搜索所有文件,非常简单方便。

回答by Himanshu padia

I had the same problem and I resolved it using some console commands.

我遇到了同样的问题,我使用一些控制台命令解决了它。

1) Open Terminal on your Mac

1) 在 Mac 上打开终端

2) run "grep -i -r --include=*.xib "searchtext" /your/project/path" command

2) 运行“ grep -i -r --include=*.xib "searchtext" /your/project/path" 命令

It will search in the path "/your/project/path" and will print the complete path of all files xib that use the "searchtext".

它将在路径“/your/project/path”中搜索并打印使用“searchtext”的所有文件xib的完整路径。

Hope this will help you!

希望能帮到你!

回答by ort11

This works if you use as service....

如果您用作服务,这将起作用....

on run {input, parameters}

 display dialog "XIB Search Text" default answer ""
 set searchtext to text returned of result

 if (length of searchtext) is greater than 0 then

   tell application "Xcode" to set theProjectPath to (the project directory of front project)

   tell application "Terminal"

    set newWin to do script "cd " & theProjectPath & "; " & "rm " & theProjectPath & "/searchXIB.txt 2> /dev/null ; grep -i -r --include=*.xib " & searchtext & " . > searchXIB.txt ; exit"
    activate

    repeat while (exists newWin)
     delay 1
    end repeat

    tell application "Xcode"
     set doc to open theProjectPath & "/searchXIB.txt"
     activate
    end tell

    tell application "System Events"
     keystroke "f" using {command down}
     keystroke searchtext
    end tell
   end tell 
  end if
 return input
end run