The normal introspection facilities can be used to introspect Objective-C classes as well. This document describes some differences between Objective-C classes and normal Python classes that might cause confusion, as well as some additional introspection mechanisms.
dir() function is used to check which attributes
are available on a class or instance, and can be used without
problem on Objective-C classes.
There is a significant difference between regular Python
classes and Objective-C classes w.r.t. class methods:
Objective-C class methods are methods defined on a meta
class, and do not use the
Because of this
dir(NSObject) only lists instance methods,
and not class methods, use
dir(type(NSObject)) to list
the class methods of an Objective-C class.
Class methods are methods on a meta class because Objective-C
classes can have class- and instance-methods with the same
name, for example
+[NSObject description] and
For python versions earlier than 3.4 the prototype of methods lists
... instead of an actual argument list. That’s due to a
pydoc w.r.t. functions implemented in C.
The documentation string does list a full prototype, and
information about arguments.
Function and method metadata¶
Objective-C methods and functions have an
that can be used to retrieve the information that the bridge
has about a specific method or function.
The result of this function is a copy of a metadata dictionary.
The struct and opaque pointer types created by PyObjC have
__typestr__ attribute. This attribute contains the Objective-C
type encoding for variables of this type.
Introspecting instance variables¶
setInstanceVariable() can be used to introspect, and
change, instance variables of arbitrary Objective-C objects,
irrespecitive of whether or not those variables are public.
This can be useful during debugging, or when exploring the internals of a framework implementation, but shouldn’t be used in production code: instance variables aren’t part of public API and could therefore change without notice between releases. Changing instance variables can break class invariants and might cause misbehavior (including hard crashes).