Reputation: 8914
There'a a similar question here but I couldn't make use of the answers in XCode 4. I googled it but I couldn't come up with anything useful either. What's your effective method of getting this information?
Upvotes: 27
Views: 16361
Reputation: 167
This is for Xcode 11 for finding the usages of a function, it took forever to find:
Not sure why Apple made this very basic functionality so complicated
Upvotes: 0
Reputation: 7931
I think instead of doing the refactor hack above. A faster way to find variable references of a particular class is to change the name of the variable (add a letter to the end) in the defining class and hit compile. The compiler will then give you an error for every place that referenced the original variable name.
@property (nonatomic, strong) NSString * url;
becomes
@property (nonatomic, strong) NSString * urlt;
and the compiler happily tells you of every place that uses it:
Upvotes: 1
Reputation: 154725
For methods and properties, just use the Related Files menu as I describe here: https://stackoverflow.com/a/17931752/1709587
For variables, there is no easy way to specifically find references, per se (you'll need to use AppCode or the ugly, slow, cumbersome refactor hack), but you shouldn't normally need to. Public member variables are rare in Objective-C, so generally variables are only referred to within the file in which they are declared. A plain text search for the variable name using cmd+f should suffice, usually.
Upvotes: 2
Reputation: 38005
As Casebash points out here, there actually is a way to search for symbols in Xcode, but unfortunately it's not at all intuitive or convenient to use.
First, open the Search Navigator (Cmd+Shift+F) and change the Style
to Symbol References
. Then type the name of the symbol into the search box (if it's just a variable name you can select it in the code and type Cmd-E to copy it to the search field). If searching for a method, be sure to use the colon-delimited notation like so:
doSomethingForObject:withParameter:andOtherParameter:
Now if someone could convince Apple to just add a contextual menu item for this, I would be a happy camper. :)
Upvotes: 8
Reputation: 11556
Find in project, though if you are searching to change the name everywhere, better would be to use the Refactoring menu.
EDIT: You can use Refactoring to find where a specific variable is referenced. Select the variable and choose Edit->Refactor->Rename. In the refactoring screen, rename the variable (just add _ at the end or something) and click preview. it will show everywhere in the project that variable is referenced. Click on each file to see the lines where the variable is called. After you're done just cancel the refactor.
Upvotes: 30
Reputation: 1985
I highly recommend you try appCode, by JetBrains. JetBrains have a lot of experience making IDEs (yes, even more than Apple ;) and have done an amazing job with even the EAP of appCode. Find usages, plus a lot more works very nicely.
You can simply open your existing xcode project file in appCode, then Search --> Find Usages.
Upvotes: 19
Reputation: 1985
The best way is to do a full text search of the project: CMD-SHIFT-F.
Upvotes: 3