Shayne Sweeney
Shayne Sweeney

Reputation: 571

Load class file dynamically (Objective-C)

In an effort to create a sandbox for CoreGraphics development (which currently consists of performing multiple build and run attempts in order to achieve the desired effect), I was curious if there was a way to dynamically load a class file at runtime.

Much like Java's class-loader ability, I was hoping to use NSBundle or something similar to dynamically load a class into memory.

The idea would be to setup a sandbox project and only have to compile then dynamically reload the class, without having to stop and re-run the host application.

Upvotes: 3

Views: 1573

Answers (1)

Georg Schölly
Georg Schölly

Reputation: 126165

NSBundle can be used to load code dynamically. Have a look at -load.

I don't get why you want to reload such a bundle. (You can through -unload and -load.) It feels wrong, the only code that gets called again is +load and +initialize. You should just need to create a new instance of your class.

Upvotes: 3

Related Questions