Xcode: view references for a variable?

后端 未结 5 2151
天涯浪人
天涯浪人 2020-12-31 06:35

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?

For e

5条回答
  •  执笔经年
    2020-12-31 07:12

    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

    Finding references to a variable can 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:

    1. It will match all occurrences of a variable with that name, even if they're unrelated to the particular variable you're looking for.
    2. 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+f and 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?

    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' hack proposed by Karim.

提交回复
热议问题