Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Unused Methods from xcode ios

I am using xcode 9 with objective c. And i want to remove unused variable and methods from classes. I am also use this way but xcode do not warning of unused methods etc. How to find out?enter image description here

like image 225
Shahbaz Akram Avatar asked Oct 12 '17 10:10

Shahbaz Akram


People also ask

How do I remove unused code from Xcode?

Those who are looking for a way to remove unused code from Swift project, it can be done easily using Periphery. Periphery is a tool to remove unused code from Swift projects. It can detect unused function, struct, class, protocols etc.

How to remove unused images from Xcode project?

Replies. In Xcode, select the app name on the top left/resources, then on the right choose 'build phases', then expand 'copy bundle resources', then find those images by name, select them, scroll down and tap '-' below to remove the references.

How do I find unused files in Xcode?

xcutility is a tool to find and delete unused files from Xcode projects. It recursively searches through a path to find all of the path's Xcode projects and files, and will tell you which files are not referenced or built in any of your Xcode projects.


1 Answers

Unfortunately unlike C functions, getting a list of unused objc methods in the form of warnings in Xcode is tricky due to the dynamic runtime environment. Your code might, for example,create a selector from a string and then call that selector on a class or instance of one etc.

One approach I've used, however it's time consuming depending on the size of the class(es), is to open the assistant editor and position the cursor over the method you wish to inspect and select callers (see below image. Normally the default selection is counterparts).

enter image description here

If there are no callers of the method then the editor shows no results.

enter image description here

However if you do this be aware no results will also show for IBActions and overrides in subclasses of iOS frameworks etc. You need to really know the code to determine if 'no results' really means no callers!

like image 99
Bamsworld Avatar answered Oct 05 '22 21:10

Bamsworld