Detecting unused methods iOS - ios

Very simple question and hopefully isn't duplicated :).
The situation is following:
Project has been developing more then a year and by many developers.
From time to time I'm facing with unused methods (which are defined in .h and .m) obviously I'm not getting any warnings.
This is not critical, but I would like to have project cleared from all unnecessary staff. Of course I can search for all methods and define which are unused in project but I wonder if there is more elegant way?!
Thanks

A quick way to check while browsing your source code is the View > Standard Editor > Show Related Items menu (shortcut key: ^1). Place your cursor within a method body and then view the Callers.

AppCode (http://www.jetbrains.com/objc) can tell you if a method or an import is unused.
It's works in real time, but you can also inspect a whole project (menu code > inspect Code)
I don't think xCode can do it.
AppCode is not free, but it has a trial version.

Might I suggest adding an NSLOG to these methods. For example, if you have a View Controller called Home, you can go into the .m file for the Home View Controller and at the top of the function, write the following:
NSLOG(#"Method 1, has 3 buttons);
then watch the readout as you progress through the actions on that View Controller. The log should say something that would best describe the method in question. Step 2 would be to take the methods that you feel aren't showing up on the output and comment them out. That can be done by highlighting the method and then hitting Command + '/' on the keyboard. This will place '//' in front of each highlighted line commenting it out. Test your view controller again and if still no errors, you can delete that method. That's a free way to do it, but it does take some time.

Related

How to avoid AppBuilder removing pieces of code

I'm working on a Progress-4GL programming environment, based on AppBuilder release 11.6.
Until now I've been changing already existing *.w and *.p files, but now I wanted to created my *.w file from scratch.
I've created a window and I've put a browse, a fill-in field and a button. Now I would like to add an event to that button. In order to do that, I add following lines to the *.w file:
ON CHOOSE OF btn-Start_Query IN FRAME DEFAULT-FRAME
DO:
MESSAGE "button is pushed" VIEW-AS ALERT-BOX.
END.
However, when I save the *.w file, re-open it in the AppBuilder and save the file there again, those lines of code get removed.
I've already understood that, in order to avoid this, I need to "wrap" those lines of code by Scoped-define or Analyze:suspend/resume lines, something like this:
&Scoped-define SELF-NAME btn-Start_Query
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btn-Start_Query C-Win
ON CHOOSE OF btn-Start_Query IN FRAME DEFAULT-FRAME
DO:
MESSAGE "button is pushed" VIEW-AS ALERT-BOX.
END.
&ANALYZE-RESUME
However, this seems not to be working.
Can you explain me what exactly I have to do in order avoid my lines of code to be removed?
By the way: I know that I'm working with extremely outdated technology, but I only work here for two weeks, so I don't have the authority to force my boss to change his development environment, just for me.
The recommended approach is to use the Wizards of the AppBuilder to create the trigger block with the required AppBuilder markup for you.
Add the button to the Window
Select the button on the design canvas
Choose the "Edit code" button in the AppBuilder main window (the pencil)
This will create an empty default trigger block (in case of a button, that's the CHOOSE). To create a different event, use the "New..." button in the section editor window.

Atom - Nested snippets with tab stops error

I just started using Atom for LaTeX, and i use a lot of snippets to make my life easier.
Now, this often means that i will "nest" snippets, meaning i might use a snippet for a fraction ...
\frac{$1}{$2} $0
... and then insert another snippet inside of this one, e.g.
\sqrt{$1} $0
Now, i have an issue where the pointers "break" when nesting the snippets. So, when i insert the square root snippet into the fraction snippet, the function to tab into the next pointer continues for the squareroot snippet, but breaks for the fraction snippet.
Is there a way to circumvent this?
Thanks :)
As of December 2018... this has been an issue for a while now. Atom's snippets package doesn't do well when trying to insert a snippet with tab stops into another snippet with tab stops. You can view the issue here:
https://github.com/atom/snippets/issues/152
Also, there has been a pull request to fix the issue, but it hasn't been merged into the master branch... and it's quite old and because of that, the patch has some file conflicts so you can't just apply the patch without resolving those conflicts. You can view that pull request here:
https://github.com/atom/snippets/pull/192
This may be fixed in the future, but I wouldn't hold my breath. Your best bet for fixing this issue is to either fork the snippets package and create your own that works as expected or to try to use the code here to patch your local copy of the snippets package

attempt to index field '' (a nil value)

I was trying to run this script done by SethBling, but it gives me this error:
LuaInterface.LuaScriptException: DP1.state
LuaInterface.LuaScriptException: [string "main"]:337: attempt to index field 'neurons' (a nil value)
This is the code
In case this didn't solve your problem try this:
"If you are using a version of BizHawk that is over 2.0, go into the menu and Click Config then follow as such: Customize > Advanced > Lua Core > Lua+LuaINterface. This is why I wasn't able to load." from JaRetroYT over on reddit.
A flamanis posted this comment on youtube. I followed the instructions and got it working.
HOW TO GET IT TO WORK! THIS ALL TAKES PLACE INSIDE THE FOLDER YOUR BIZHAWK EMULATOR IS IN.
Execpt this part: Before EVER opening the lua console on BizHawk,
(If you have, instructions on how to reset your stuff will be at the
bottom) go onto the level you want to have it learn, and when the
level starts up, click on file. Go down and open the menu of save
state, at the bottom click the create named state, and then finally
name it DP1, however put it after all the slashes and whatever so just
delete the gamestate.whatever jargon that it auto names it. After
doing that, either move that file from the SNES/State folder to where
you have your lua file, or the other way around. and then load up the
lua file into the console, and boom you're good.
IF YOU ALREADY TRIED TO RUN THE LUA FILE AND IT ERRORS: You either need to delete your save, or edit the lua file slightly. If you want to do the delete save approach, then go into the SNES folder and then into the SaveRAM
folder and delete your file for the game. THIS DOES NOT DELETE THE
EMULATION, just the save. If you want to edit the lua file, then at
the top, the very top line, (create a new one if you want to, just
make sure it's before any other text) add this: pool = nil that's it.
It will reset the data so that it can run again. You still need that
save state though. You will probably want to edit the file again after
you've started running it and remove that line or it will restart
every time you turn it on.
Alrighty, I said I'd answer this better, and sometimes people do just google randomly for their solutions.
Soo, Bizhawk emulator has a way to run Lua scripts, which is nice.
So Seth's program assumes a few things about how the game is set up, and how the user (that is you) has done certain things beforehand.
The main thing that you need to do beforehand is create what is known as a save state. This is a point in the game that you can instantly reload back to, and how the program restarts the level so that each 'run' is essentially the exact same. This differs slightly from normal games where you 'load' the game, because games back around SMB weren't as 'random' as games now. So saving the game and loading it should give the same exact result with the same inputs every time.
You should create the save state right at the very start of the level. To create this illustrious save state you want to click on the file button at the top of your screen to open the drop down, and then select save state and create a new one. This should create a save state that you can then load to return to that exact moment in the game.
To have the program be able to load your save state to run you can do one of two things
1: Rename the actual save state file name to be just DP1.savestate
2: Modify the Lua file and change the DP1.savestate part to be the name of your save state
Then you just need to move them into the same folder, and you should be golden.
If you attempted to run the file before making a save state, it will have tried to run and errored with attempt to index field 'neurons' (a nil value) or something similar. (It's been a while, it could have stopped on the first run because it couldn't find the save state, so this might just only happen on the 2nd and further runs)
What this means is that it essentially created it's "brain" but left it completely empty. Which is bad. There's two ways to fix this, and they're fairly straightforward.
1: You need to delete the actual game save, otherwise known as the SaveRAM. The file that you need to delete can be found in the folder for whatever console you're running, in Seth's video he was using the SNES, so that's the folder you'd want to go into. Inside that folder is then the SaveRAM folder, you can either just delete that folder, or go into it and delete the one for the game you were running.
2: You need to edit the Lua file to reset itself, all this requires is putting the text pool = nil at the very top. This will then delete the "brain" before anything else happens, which will let the program create a new one. Fair warning: This is not just a one time effect, if you restart the program at this point you will lose your entire progress. What you need to do is after it starts running, stop it and edit the file again, and remove the line you just added. This will stop it from deleting it's "brain" every time the program starts, and you should be able to freely run the game.
I do hope that there are still people who look at Seth's video and wants to make it run themselves, good luck to you guys, and happy gaming.
"If you are using a version of BizHawk that is over 2.0, go into the menu and Click Config then follow as such: Customize > Advanced > Lua Core > Lua+LuaINterface. This is why I wasn't able to load."
from JaRetroYT over on reddit.
Move the savestate and lua script to the main folder for the emulator (where EmuHawk.exe is)

Delphi: How to debug run until you get back to your source file?

If I run a program and an exception is raised I am asked if I want to continue or break.
If I choose break I can see where the exception is coming from but if the break is in a library or system file not one of my source files (Say the exception is in System.pas or Controls.pas) I need to manually step the execution forward using F8 until it returns to one of my files, so I can see what part of my code caused the exception.
This can take a long time.
I know I should be catching lower level exceptions in my code but in this instance it's not hitting one of my exception handlers.
Is there a way to say
run forward with execution until you get to file X or
until you get back into a project specific file.
I'm also interested out of general curiosity on how other compilers / IDEs handle this.
Apologies if I haven't made this as clear as a I should.
You can resolve this by using the Stack View window.
Open the Stack View window (CTRL+ALT+S).
Double click on the method in the stack view where you wish to insert a breakpoint.
The unit, containing the caller method opens and the cursor is positioned on the caller method.
Set your breakpoint.
There's an even simpler way than Lieven's suggestion. Follow the first 3 steps as he laid them out, but don't place a breakpoint.
The problem with placing a breakpoint is that you have to clear it afterwards or you'll end up getting dropped into the debugger every time you pass that line. If you only want to run to a certain line and then drop to the debugger once, put the cursor on that line (the insertion point, not the mouse cursor) and press F4 (Run to Cursor). It's like a one-time breakpoint.
There are several ways:
Use the "Next source line" function (Shift+F7)
Use the call stack and double-click on the function you need, add a breakpoint there and hit "Run" (F9).
Use the "Step out" (Shift+F8) function until you are back into your own code.

Mysterious assets used in swf, not found anywhere in fla?

near the top of the code i see things like,
btn_dropdown._visible = false;
mcMenuBkg._visible = false;
but I can't find these assets anywhere in the library or in any code, how does this make any sense?
The movie clips in the library that look the same have different names and I can delete them entirely and they still show up when I compile and run, or I can add trace statements into their code and they never get called.
where on earth are these assets defined?
In theory, any clip you see at runtime could be dynamically created, by making an empty MC and drawing in whatever contents you like with the drawing API. However, if you see clips in the library that are similar to what's showing up at runtime, then it's very unlikely that that's happening.
Your first step should probably be another look through the library. Remember that instance names don't have to be the same as MC names; even if something is called "Menu Holder" in the library there might be an instance of it somewhere called "mcMenuBkg" or whatever. But the fact that you can delete stuff without changing the output is mysterious.
So, other possibilities: contents are being loaded externally, or imported via runtime sharing. If feasible, try moving your SWF to a temp directory and running it from there; that should break all loads (unless contents are loaded from a remote URL).
Or, you're looking at the wrong clips in the library. If it's a crufty project there may be unused stuff in there. Try expanding the library wide enough to see the "Use count" column, and select "update use counts" from the library menu. Anything with a count of 1 or higher is part of your FLA's stage content - either it's sitting on the main stage or it's a child of something that is. Clips with a use count of 0 may still be used if they have a linkage ID; they could be created at runtime with attachMovie(). However, for any clip with a use count of 0 and no linkage id, it's safe to assume that it's unused, and irrelevant to what happens at runtime.
If none of that helps, the only things that come to mind are sanity checks... open up everything on the stage and every clip with a linkage id, and check for empty/invisible MCs. Check the Movie's export settings to make absolutely sure the SWF you're checking is the same one being published. And just for grins, open up the "Scenes" panel and make sure that some diabolical fiend hasn't put important content on a separate scene where no sane man would look for it.
Vague answer for a vague question. :D Hope it helps...
You can create movie clips with code dynamically.
This means that you may not have them in your assets if you are unable to find them.
You can create any type of symbol using a constructor out of thin air with actionscript alone.
I would search the code for one of these
var mybutton:SimpleButton=new SimpleButton();
If they're being set to
_visible = false
you won't see them anyway - and as ActionScript 1/2 doesn't do runtime error reporting, the Flash player won't complain if they're not actually there on the stage. If they're not being used, just delete them.

Resources