5. Dynamic Creation
Cocoa utilizes many features of the underlying Objective-C runtime. One powerful feature is the ability to create instances of classes that did not exist at the time an application was compiled and dynamically load and link new classes at runtime. Scripting languages such as AppleScript, Tcl, Ruby, Perl, and Python use this technique to provide interfaces to Cocoa. The core of this pattern is the NSClassFromString() function that returns the class object with a specified name. NSBundle augments this by implementing the method –classNamed:, which can dynamically load code for the class if necessary. Once the named class object is obtained, instances can be created.
Dynamic creation enables scripting language bridges, plug-ins, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access