Finding all references of a variable or a method in Xcode4 - reference

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?

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.

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.

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. :)

The best way is to do a full text search of the project: CMD-SHIFT-F.

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.

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:

This is for Xcode 11 for finding the usages of a function, it took forever to find:
Right click the name of the function.
Select "Show Code Actions"
Select "Callers..."
Not sure why Apple made this very basic functionality so complicated

Related

Search-Everywhere in Android Studio (IntelliJ) makes Search File redundant?

In Android Studio (and IntelliJ), shift-shift is used to Search File (and Everywhere, e.g. class name etc).
I just realize it also have shift-command-O that search for a file.
With shift-shift, it seems to me shift-command-O is redundant.
So I'm checking to see if I have miss something that is in shift-command-O but not in shift-shift?
Shift-Shift shows a popup with occurrences of the string you've entered in names of files, classes, symbols and actions. Shift-Command-O shows a popup with occurrences of the same string only in names of files. Same task, same UI (in recent IJ/AS versions) more narrow filter.
Well you're almost right but there is one main difference in those two commands.
Shift shift will search for a file.
While shift-command-o will go to the specified file.
I guess in a way they to de same, but if you use Shift-command-o you will be redirected to that file and saves you one click.
But feel free to use what you want, shortcuts are for convenience so you should use what is most comfortable.
Here is a link with all shortcuts in IntelliJ IDEA, could be usefull in the future :)
https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf

Sublime, altering behavior of highlighting definions upon mouse-hover

I have a project with several classes which partly share functions while at other times the functions are different in code, but use the same name.
When hovering over a function name, Sublime highlights every file and line where that definition is found.
In my opinion it would be better if it actually included which class the different highlights belong to.
Is it possible to edit this in some way ?
Assume systems.js contains 4 different classes (1 base, 3 children). I would like to append or prepend the shown strings by the class definition (fetchable via prototype).
The hover popup mentioned in your question is powered by Sublime's internal symbol index, which is created in combination with the syntax definition that's used to syntax highlight files that you're editing. The Sublime syntax system is fairly context free; it parses the structure of the code but it doesn't contain any real structural information about it.
So for example it can determine that getShots is a function or method because of the syntax that was used to define it, but it doesn't know what class it came from.
The code for the hover popup is available in Default/symbol.py (you can use PackageResourceViewer to examine it) and associates symbols under the cursor with other places that it's seen symbols with that name in other files in the project; it literally only knows the information that you see in the popup; places where things by that name are defined and places where things of that name are referenced.
So in one sense, the answer to your question is No; core sublime can't do that because it doesn't have enough code intelligence to be able to figure that sort of thing out; this is exacerbated by dynamic languages like JavaScript where things can theoretically change at runtime as well.
The primary reason for that is because Sublime is extensible enough to support literally every programming language instead of just focusing on one or two (as e.g. PhpStorm does), so it doesn't have the core code to determine the information required.
All that said, since Sublime is indeed extremely extensible, it's possible that external code that does specialize on a language could be leveraged by a package in order to provide the appropriate information.
Two examples of that are SublimeCodeIntel and LSP for example. I don't use either of them myself, so I don't know for sure how good a fit they might be in your workflow.
I highly recommend you shift to Visual Studio Code majorly because sublime is an editor whereas vs code is an IDE. Also, it has very great extension support for all languages. I would recommend you to use jshint which the most popular plugin for js code available for almost all popular editors and IDEs. But still if you want to go with Sublime I suggest you following plugins:
https://www.sitepoint.com/essential-sublime-text-javascript-plugins/

Do a Find in Current Namespace in Visual Studio?

Want to be able to do a Find but contain my results to the current namespace the current opened file is in. Like "Current Project" but "Current Namespace". Is there a plugin or tool that can do this?
You can always use a regex :
namespace my_namespace(.*\n)*.*my_search
That's kind of an ugly solution, since it will select everything between namespace keyword and you search. But that's still useful.
You can adapt it and change capture groups in order to be able to use it for replacements.
Rather than parsing and inspecting every code file individually, Agent Mulder plugin utilizes ReSharper's Structural Search (sometimes known as Structural Search and Replace, or SSR) to look for patterns of code in the entire solution. This is both effective (since the solution structure already exists in ReSharper's caches), and makes it very easy to extend Agent Mulder to support additional containers.
Here is an overview of ReSharper's Structural Search API (based on ReSharper SDK v6.1)

Chose a color for a particular method in VS2012

Pretty dumb question I know,
I want to know if there is a way to assign a particular color to a method of my choice in .cs file.
So that i donot even accidently go and write or change anything there.
No, Visual Studio does not support this behavior natively (though someone could write an extension that did it).
Some ideas, though...
My first suggestion is to use version control so that any changes you make can be reviewed and reverted.
My second is, in C# you could use a partial class to keep all the code that should never change in one file and the code you can change in another file. You could even go further and set the readonly flag on the file you never want to change (though check how this affects your source control system).
But use version control either way.

Vim Plugin: Follow Symbol under Cursor

Is there a vim plugin that allows you to place the cursor over a function and have a plugin run a script that searchs a tag or some other entity for where that function is defined. Or perhaps it provides a list of places where that function is defined? Specifically I am looking for a C/C++ based plugin.
You want ctags, which supports many, many languages beyond C. It will show you the definition of the function or variable under the cursor.
cscope integrates nicely with Vim to do exactly that and more. Where a function is defined, where it is called etc. You may also need a tags with cscope.
The vim website hosts a lot of plugins, you might really want to look there. Also, you didn't really specify what languages you wanted this to apply to, so this is a very broad question (hard to find a real answer to this).
An alternative to your question is, instead of putting the lookup capability into vim, why not put in into something else that already has it? Why not eclipse? There's an eclipse plugin called vrapper that gives vim like functionality within eclipse. You can then use eclipse to do the referencing and lookup that you want to do, because it already has this supported for many languages.
Edit: wouldn't this solve it?
I think you wanted to know what it was that you had to do to be able to solve the problem, as though you knew the feature was there but not how to use it. That link explains it. If that is the solution to your problem, please remember to vote & check XD

Resources