Skip to content

Latest commit

Β 

History

History
136 lines (122 loc) Β· 4.01 KB

File metadata and controls

136 lines (122 loc) Β· 4.01 KB

objc-class-tree can print a nice tree of Objective-C classes.

By default, it will print a huge tree of all the classes loaded in its own binary:

$ objc-class-tree | head -30
NSProxy
_NSZombie_
__NSMessageBuilder
__NSGenericDeallocHandler
Object
NSObject
β”œβ”€β”€ OCTMethod
β”œβ”€β”€ OCTTreeFormatter
β”œβ”€β”€ NSURLDownload
β”œβ”€β”€ NSXPCInterface
β”œβ”€β”€ NSAppleEventDescriptor
β”œβ”€β”€ NSFileWrapper
β”‚Β Β  β”œβ”€β”€ NSFileWrapperLink
β”‚Β Β  β”œβ”€β”€ NSFileWrapperDirectory
β”‚Β Β  └── NSFileWrapperFile
β”œβ”€β”€ NSURLSessionConfiguration
β”œβ”€β”€ NSSpellEngine
β”œβ”€β”€ NSXMLParser
β”œβ”€β”€ NSXMLNode
β”‚Β Β  β”œβ”€β”€ NSXMLElement
β”‚Β Β  β”œβ”€β”€ NSXMLDTDNode
β”‚Β Β  β”œβ”€β”€ NSXMLDTD
β”‚Β Β  └── NSXMLDocument
β”œβ”€β”€ NSValueTransformer
β”‚Β Β  └── _NSSharedValueTransformer
β”‚Β Β   Β Β  β”œβ”€β”€ _NSUnarchiveFromDataTransformer
β”‚Β Β   Β Β  β”œβ”€β”€ _NSKeyedUnarchiveFromDataTransformer
β”‚Β Β   Β Β  └── _NSNegateBooleanTransformer
β”‚Β Β   Β Β   Β Β  β”œβ”€β”€ _NSIsNotNilTransformer
β”‚Β Β   Β Β   Β Β  └── _NSIsNilTransformer
$ objc-class-tree | wc -l
     401

You can limit its output to a handful of class trees by using the --root-class option:

$ objc-class-tree --root-class NSArray --root-class NSXMLNode
NSArray
β”œβ”€β”€ NSKeyValueArray
β”œβ”€β”€ __NSOrderedSetArrayProxy
β”œβ”€β”€ __NSArrayI
└── NSMutableArray
 Β Β  β”œβ”€β”€ NSKeyValueMutableArray
 Β Β  β”‚Β Β  β”œβ”€β”€ NSKeyValueNotifyingMutableArray
 Β Β  β”‚Β Β  β”œβ”€β”€ NSKeyValueIvarMutableArray
 Β Β  β”‚Β Β  β”œβ”€β”€ NSKeyValueFastMutableArray
 Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ NSKeyValueFastMutableArray2
 Β Β  β”‚Β Β  β”‚Β Β  └── NSKeyValueFastMutableArray1
 Β Β  β”‚Β Β  └── NSKeyValueSlowMutableArray
 Β Β  β”œβ”€β”€ __NSPlaceholderArray
 Β Β  └── __NSCFArray
NSXMLNode
β”œβ”€β”€ NSXMLElement
β”œβ”€β”€ NSXMLDTDNode
β”œβ”€β”€ NSXMLDTD
└── NSXMLDocument

You can ask it to output implemented methods:

$ objc-class-tree --root-class NSURLResponse --methods
NSURLResponse
β”œβ”€β”€ - init
β”œβ”€β”€ - dealloc
β”œβ”€β”€ - copyWithZone:
β”œβ”€β”€ - initWithCoder:
β”œβ”€β”€ - encodeWithCoder:
β”œβ”€β”€ - URL
β”œβ”€β”€ - _CFURLResponse
β”œβ”€β”€ - _initWithCFURLResponse:
β”œβ”€β”€ - initWithURL:MIMEType:expectedContentLength:textEncodingName:
β”œβ”€β”€ - suggestedFilename
β”œβ”€β”€ - expectedContentLength
β”œβ”€β”€ - textEncodingName
β”œβ”€β”€ - MIMEType
β”œβ”€β”€ + _responseWithCFURLResponse:
└── NSHTTPURLResponse
 Β Β  β”œβ”€β”€ - initWithCoder:
 Β Β  β”œβ”€β”€ - statusCode
 Β Β  β”œβ”€β”€ - _initWithCFURLResponse:
 Β Β  β”œβ”€β”€ - initWithURL:statusCode:HTTPVersion:headerFields:
 Β Β  β”œβ”€β”€ - initWithURL:statusCode:headerFields:requestTime:
 Β Β  β”œβ”€β”€ - _peerTrust
 Β Β  β”œβ”€β”€ - _setPeerTrust:
 Β Β  β”œβ”€β”€ - _clientCertificateState
 Β Β  β”œβ”€β”€ - _clientCertificateChain
 Β Β  β”œβ”€β”€ - _peerCertificateChain
 Β Β  β”œβ”€β”€ - allHeaderFields
 Β Β  β”œβ”€β”€ + supportsSecureCoding
 Β Β  β”œβ”€β”€ + isErrorStatusCode:
 Β Β  └── + localizedStringForStatusCode:

It can also display protocols and which libraries the classes come from:

$ objc-class-tree --root-class NSString --protocols --library-names
NSString <NSCopying, NSMutableCopying, NSSecureCoding> (Foundation)
β”œβ”€β”€ NSSimpleCString (Foundation)
β”‚Β Β  └── NSConstantString (Foundation)
β”œβ”€β”€ NSPathStore2 (Foundation)
β”œβ”€β”€ NSLocalizableString <NSCoding, NSCopying> (Foundation)
β”œβ”€β”€ NSPlaceholderString (Foundation)
└── NSMutableString (Foundation)
 Β Β  β”œβ”€β”€ NSPlaceholderMutableString (Foundation)
 Β Β  β”œβ”€β”€ NSMutableStringProxyForMutableAttributedString (Foundation)
 Β Β  └── __NSCFString (CoreFoundation)
 Β Β   Β Β  └── __NSCFConstantString (CoreFoundation)

See main.m for more supported options.

Building

Build using Meson as usual:

$ meson build
$ cd build
$ ninja build
# optionally
$ sudo ninja install

License

objc-class-tree is free software, available under the GNU General Public License version 3 or later.