Visualize iOS App’s Dependency Graph
Understand what’s going on with your project
It’s really important for a developer to understand what’s the dependencies among the objects in a project. Without analysing it properly, it often happens that you introduce some memory leak and you don’t even aware of it.
Xcode provide debug memory graph to simulate run time objects in our memory and there dependencies. It’s a great tool to analyse.
There also have some 3rd party tools which quite helpful to understand, visualize the run time objects and there dependencies. One of them is
Objective-C And Swift Dependencies Visualizer
let’s use it.
clone the repo using below cmd and go to the directory.
git clone https://github.com/PaulTaykalo/objc-dependency-visualizer.git
now run your project in xcode. Then execute the below cmd in terminal.
./generate-objc-dependencies-to-json.rb -d -s "" -p /path/to/YourProject> origin.js ;
It will take your project from driver data and write your projects object dependency graph into index.html. So in /path/to/YourProject must give your project driver data location. Now open the index.html.
open index.html
it will show something like below
Here you can saw the all classes and there relationship.
If you click a single class you are able to saw it’s dependencies very well.
Here I click CurrencyExchangeViewModel class.
What about that you want to analyse only one class and it’s dependencies?
yes, it possible using this cmd. Here MyClass is your target class.
./generate-objc-dependencies-to-json.rb -s "MyClass" -p /path/to/MyProject > origin.js
What about you want to exclude one class from the analysis?
Yes, you can using below cmd. Here all the classes start with Private_ will exclude.
./generate-objc-dependencies-to-json.rb -s "" -p /path/to/MyProject -e "Private_*" > origin.js
You can also change the colour code according to you types by editing below code.
Resources:
Those who follow or read comment down if you have questions. If you want to connect, knock me on LinkedIn. Happy coding and stay safe.