17

How can you find all references to a Swift class variable in Xcode?

The answers I've seen (such as the selected answer of Finding all references of a variable or a method in Xcode4) are only applicable to Objective C.

Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

3 Answers3

19

Control-click on the symbol and click Find > Find Selected Symbol in Workspace.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
18

Xcode is not very strong when it comes to code analysis. You are however left with 2 options:

  1. Rename the variable definition temporarily and compile the project. All usages of the variable won't find it anymore and provoke an error – hence every compile error is a usage of your variable. By selecting the error you navigate to the variable usage.

  2. Use another IDE that has code analysis capabilities such as AppCode from JetBrains. Besides an intelligent search it also comes with clever refactoring facilities.

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
  • 6
    In 2019 XCode probably is the worst IDEA in the software world. I am so happy that I started with Android. At the moment iOS devs have issues, which Android had 2012. – Stoycho Andreev Jul 04 '19 at 16:15
2

In Xcode you can find references of the variable Find >References >Matching in Find Navigator in Left Navigator But be careful it will give you all the references matching the variable name so you must to be careful with that, until now this feature not implemented in a good way to find the references like other IDE's.

This is the most efficient way you can do until now.

enter image description here

Ali Omari
  • 371
  • 3
  • 11
  • 2
    User is asking to find all references not just a text search – RiceAndBytes Sep 13 '17 at 17:07
  • AliOmari's answer is correct, that is the closest you can currently get to what the OP is asking. A `text search` as you call it is a different option which is not the same as a `reference search`. – Manuel May 25 '20 at 20:30