在 Xcode 中查找方法引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7145045/
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-09 04:04:37  来源:igfitidea点击:

Find method references in Xcode

xcodeide

提问by Java Ka Baby

Is there a way in Xcode to find all the places where a method or property has been been called?

有没有办法在 Xcode 中找到所有调用方法或属性的地方?

In Eclipse, for example, you can right-click a method and select Find references. Is there anything similar in Xcode?

例如,在 Eclipse 中,您可以右键单击一个方法并选择Find references。Xcode 中有类似的东西吗?

回答by Mark Amery

  1. Select the method you're interested in, or position the text cursor within it.
  2. Open the "Related Files" menu via the icon at the top-left of the Editor. (It's the button immediately to the left of the back button).
  3. Go to the "Callers" submenu for a list of all methods that call the selected method, and click any of them to jump to that file and method.
  1. 选择您感兴趣的方法,或将文本光标置于其中。
  2. 通过编辑器左上角的图标打开“相关文件”菜单。(它是后退按钮左侧的按钮)。
  3. 转到“调用者”子菜单以获取调用所选方法的所有方法的列表,然后单击其中任何一个以跳转到该文件和方法。

In pictures...

在图片...

Screenshot of steps 1 and 2 above.

上面第 1 步和第 2 步的屏幕截图。

Screenshot of step 3 above

上面第 3 步的屏幕截图

A couple of notes:

一些注意事项:

  • You can do this for properties too.
  • Note that when you select a calling method from the Callers menu to jump to where your method was called, Xcode highlights only the firstcall. Each calling method will only show up in the 'Callers' list once, even if it contains many calls to your method. So if you're trying to make some change at every place in your application where a method is called, be careful not to miss some in places where a calling method contains two calls to the method you're interested in.
  • 您也可以对属性执行此操作。
  • 请注意,当您从 Callers 菜单中选择一个调用方法以跳转到调用您的方法的位置时,Xcode 仅突出显示第一个调用。每个调用方法只会在“调用者”列表中出现一次,即使它包含对您的方法的许多调用。因此,如果您试图在应用程序中调用方法的每个地方进行一些更改,请注意不要在调用方法包含对您感兴趣的方法的两次调用的地方错过一些更改。

回答by Alex Terente

Yes, open the Assistant editor and instead of Counterparts select Callers.

是的,打开助理编辑器,然后选择呼叫者而不是对方。

enter image description here

在此处输入图片说明

回答by SystematicFrank

As of XCode 4.5 you can click on "Show find options" within the search field of the Search Navigator. There you can specify "Symbol References"

从 XCode 4.5 开始,您可以在搜索导航器的搜索字段中单击“显示查找选项”。在那里您可以指定“符号引用”

enter image description here

在此处输入图片说明

回答by Uladzimir

Select function, press cmd-shift-A, "Callers"

选择功能,按cmd-shift-A,“来电”

enter image description here

在此处输入图片说明

回答by Nicholas Riley

Place the insertion point in a method invocation or declaration and choose Find > Find Selected Symbol In Project. For multipart selectors this will only highlight the first part but searching does seem to work relatively reliably. You can also use Find Call Hierarchy which highlights the entire line instead.

将插入点放在方法调用或声明中,然后选择 Find > Find Selected Symbol In Project。对于多部分选择器,这只会突出显示第一部分,但搜索似乎工作相对可靠。您还可以使用 Find Call Hierarchy 来代替高亮显示整行。

The corresponding contextual menu item (Find Selected Symbol in Workspace) also works, but it's a bit trickier to make work properly. Make sure no text gets selected otherwise it'll search for the selected word rather than the entire selector. To do so, you can click with the left mouse button prior to clicking with the right mouse button (or Control-clicking) in the same location. There's no such issue with the contextual Find Call Hierarchy.

相应的上下文菜单项(在工作区中查找选定的符号)也可以使用,但要使其正常工作有点棘手。确保没有选择任何文本,否则它将搜索所选单词而不是整个选择器。为此,您可以先用鼠标左键单击,然后在同一位置单击鼠标右键(或按住 Control 键单击)。上下文 Find Call Hierarchy 没有这样的问题。

回答by Scott Looze

With xcode 4 you can now right click on references and select "jump to definition."

使用 xcode 4,您现在可以右键单击引用并选择“跳转到定义”。