This guy came up with a pretty neat tool to generate a class dependency graph - however, it relies on parsing your source code and looking for #import
directives.
This is neat, but I have a number of problems with this. Not least of which is it doesn't take into account imports of imports nor prefix headers nor whether-or-not the class(es) in the file referenced by the import are actually being used.
I'd like to do something more akin to class-dump
and examine the Objective-C metadata stored in the Mach-O file to generate an in-memory representation of the class dependencies.
I'd rather not do this from scratch, so I'm wondering:
Has it already been done?
Not that I know of.
Is there an open-source library which would provide me with the foundational tools I need to extract this information?
At the core of class-dump is libMachObjC
which does exatly what you want, i.e. parse all classes/methods/ivars and more. The API is very clean, it should be very easy to use.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
Unfortunately, no because some classes don't declare the real class but use id
instead. For example, here is the information that can be extracted from a class-dump of UIKit:
@interface UITableView : UIScrollView <NSCoding>
{
int _style;
id <UITableViewDataSource> _dataSource;
id _rowData;
...
The _rowData
ivar type information is id
but if you check at runtime you will see that _rowData
is an instance of the UITableViewRowData
class. This information is not present in the Mach-O binary so you have no way to find the relation between UITableView
and UITableViewRowData
. The same applies for method parameters.
Here's a solution that relies on information in mach.o files, and generates graph dependency based on that information: https://github.com/PaulTaykalo/objc-dependency-visualizer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With