Xcode:查看变量的引用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2831845/
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
Xcode: view references for a variable?
提问by David.Chu.ca
I am new to Xcode. I am not sure if there is a way to view a variable's references just like "Find all references" in Visual Studio by right click on a var?
我是 Xcode 的新手。我不确定是否有办法通过右键单击变量来查看变量的引用,就像 Visual Studio 中的“查找所有引用”一样?
For example, in my .h file, I would like to know or view all the references for property isSet:
例如,在我的 .h 文件中,我想知道或查看属性 isSet 的所有引用:
@interface MyInterface {
...
BOOL isSet; // view all references to this var?
...
}
采纳答案by TOP KEK
Beside Xcode, there is AppCode IDE from JetBrains. And in AppCode it is easily possible, just select Search
--> Find Usages
.
除了 Xcode,还有来自 JetBrains 的 AppCode IDE。在 AppCode 中很容易实现,只需选择Search
--> Find Usages
。
回答by Casebash
Try using: Find in project -> As symbol context menu. Sometimes you may want to search as definition instead.
尝试使用:在项目中查找 -> 作为符号上下文菜单。有时,您可能希望搜索为定义。
回答by karim
I was looking for similar option. I do not know why XCode did not included that. But there is a work around I use until Apple give that option in XCode.
我正在寻找类似的选择。我不知道为什么 XCode 没有包含它。但是在 Apple 在 XCode 中提供该选项之前,我使用了一种解决方法。
Try this in the source code (.m) file,
在源代码 (.m) 文件中试试这个,
Select the symbol, right click -> Refactor -> Rename
-> Give a name whatever you wish, then press Preview.
Now you can find all the references. Now you can Cancel
it or do not rename it. :)
现在您可以找到所有参考资料。现在你可以Cancel
或不重命名它。:)
回答by Mark Amery
You're conflating two different things in your question: finding references to a variable, and finding references to a property. Finding references to a property can be done via the 'Related Files' menu, as described in my answer here: https://stackoverflow.com/a/17931752/1709587
您在问题中混淆了两个不同的事情:查找对变量的引用和查找对属性的引用。可以通过“相关文件”菜单找到对属性的引用,如我在此处的回答中所述:https: //stackoverflow.com/a/17931752/1709587
Finding references to a variablecan be sort-of done via 'Find Navigator' tab of the Navigator. (That's the magnifying-glass-icon tab of the left side menu.) Go to Find
-> References
-> Matching
and type in the variable you're looking for. That said, I can't see that this is particularly useful, because:
可以通过导航器的“查找导航器”选项卡来查找对变量的引用。(这是左侧菜单的放大镜图标选项卡。)转到Find
-> References
->Matching
并输入您要查找的变量。也就是说,我看不出这特别有用,因为:
- It will match all occurrences of a variable with that name, even if they're unrelated to the particular variable you're looking for.
- Why would you ever need this? You shouldn't generally be using public member variables (use properties instead), so 99% of the time, all references to the variable you're interested in will be within the file in which it is declared. Just using cmd+fand doing a simple text search within that file has always sufficed for me, and I've never felt the need to bring out heavier machinery. If you hit a couple of comments while doing this, who cares?
- 它将匹配所有出现的具有该名称的变量,即使它们与您要查找的特定变量无关。
- 你为什么需要这个?您通常不应该使用公共成员变量(改用属性),因此在 99% 的情况下,对您感兴趣的变量的所有引用都将在声明它的文件中。对我来说,只需使用cmd+f并在该文件中进行简单的文本搜索就足够了,而且我从未觉得需要使用更重的机器。如果您在执行此操作时发表了一些评论,谁在乎?
If you truly, truly do need the functionality you're asking for, and neither the 'Related Files' menu, Find
-> References
, nor a simple text search will do, then your only options are to use some third party tool like AppCode or the (cumbersome, slow) 'refactor' hackproposed by Karim.
如果您确实确实需要您所要求的功能,并且“相关文件”菜单Find
->References
或简单的文本搜索都不起作用,那么您唯一的选择是使用某些第三方工具,例如 AppCode 或(繁琐,缓慢)由 Karim 提出的“重构”黑客。
回答by zero7
i'm using xcode ver 4.5 and i can select the method or property, right click and pick Find Selected Text in Workspace...
我正在使用 xcode 4.5 版,我可以选择方法或属性,右键单击并选择在工作区中查找选定的文本...