PDA

View Full Version : A shortcut for ...




nashyo
Aug 15, 2012, 11:04 AM
Is there a shortcut for ...

Finding out where a method is called

and

Finding out where a property is set

At the moment, I can't find any kind of function that will highlight this useful information for any given method or property I have in my code. Can anyone help?

Thanks



Ides
Aug 15, 2012, 05:09 PM
I don't think there's really an official function in xcode for finding these things. But you could use Edit->Find in Workspace. That will highlight bits of code you're searching for.

Say you want to find out whenever someMethod is being called. You could do a search for "someMethod]", and that should help you locate where it's being called.

To find where a property is being called search for ".propertyName", and to find out where a property is being set search for ".propertyName ="

Duncan C
Aug 15, 2012, 07:40 PM
Is there a shortcut for ...

Finding out where a method is called

and

Finding out where a property is set

At the moment, I can't find any kind of function that will highlight this useful information for any given method or property I have in my code. Can anyone help?

Thanks

To find where a method is called, use the editor to search all files in your project for the method name (edit menu>find>find in workspace, or command shift F).

To figure out where an instance variable is being changed, there is a facility in the Xcode debugger called watchpoints. They've been broken for a while, but they seem to be fixed again in Xcode 4.4.

To set a watchpoint, stop your program at a breakpoint in the class who's instance variable you want to watch. Then go to the variables view in the debug area, open the disclosure triangle next to "self", and find the variable you want to watch. Right click on it and select the item 'Watch "<variablename>"' in the popup that appears. Watchpoints are listed along with code breakpoints in the breakpoint navigator, and you can enable and disable them as desired.

Once you've set a breakpoint, the next time your code changes that variable, the debugger will stop it and show you the line.

MattInOz
Aug 15, 2012, 07:45 PM
Also in xCode 4.4 the counterpart editor has the option to show "Callers" of the class you are editing.

Duncan C
Aug 15, 2012, 08:12 PM
Also in xCode 4.4 the counterpart editor has the option to show "Callers" of the class you are editing.

Cool. I did not know about that. Is that new in 4.4?

MattInOz
Aug 15, 2012, 08:19 PM
Yeah, they added a few new counterparts in 4.4.