tags:

views:

327

answers:

1

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.

A: 

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.

Georg
What I am looking to do is essentially introduce a bundle at runtime. Unload the bundle and reload it with a new one. I want to do this without having to stop and start the application.
Shayne Sweeney
If you don't have any references to the bundle when unloading it, you can just use `-unload`. If you _do_ have references I can't help you, I haven't got any experiences in that field. Maybe you can solve your problem using the CoreFoundation bundle support using `CFBundle`, which is quite different to `NSBundle`.
Georg