“This is the 10th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.

1. Check the methods not used in the ObjectiveC project

The preparatory work

  1. Have your own project as an example to be carried outbuildAfter,show in finder

  1. Display package contents

  1. Locate the Mach-o executable

Tools to address

Github.com/nst/objc_co…

This script method can only detect methods that the OC may not use, and is not applicable to other scenarios

Starting test

The output

  • All unused methods are listed, including those in the POD tripartite library;

The principle of

The principle uses the structure and presentation of a Mach-o file: __TEXT: __objc_methName: contains all the methods in the code; __DATA__objc_selrefs: contains references to all used methods, and all unused code can be obtained by taking the difference between the two sets.

Question:

Can’t find Implemented Methods if implemented during execution

  • Due to regular expression problems, can be changedobjc_cover.pyThe:
re_sig_sel_ios = re.compile("\s*imp 0x\w+ ([+|-][.+\s(.+)])")
Copy the code

To solve the problem

re_sig_sel_ios = re.compile("\s*imp\s*0x\w+ ([+|-][.+\s(.+)])")
Copy the code

2. Check the unused methods, attributes and classes in the Swift project

Tools to address

Github.com/zColdWater/… This script method can only detect methods, attributes, and classes that Swift may not be using

Starting test

CD < project root directory > 2. Enter the unused. Rb script file's local path to the terminal, or drag the unused.Copy the code

Such as:

The output

Xcode integration

* Tool local path (it is recommended to put the tool in the project root directory)+xcode