O'Reilly logo

Cocoa Design Patterns by Donald A. Yacktman, Erik M. Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required