atxe
atxe

Reputation: 5079

What's the point of creating classes at runtime in Objective-C?

I've recently reread the interesting tutorial from Mike Ash about How to create classes at Objective-C Runtime

I has been a long time I am wondering where to apply this powerful feature of the language. I always see an overkill solution to most of the ideas that come to my mind, and I eventually proceed with NSDictionary. What are your cases of use of creating classes at runtime? The only one I see is an Obj-C interpreter... More ideas?

Upvotes: 1

Views: 1457

Answers (3)

Catfish_Man
Catfish_Man

Reputation: 41821

KVO, in the Cocoa frameworks, is implemented by dynamically creating "notifying" versions of your classes. See http://www.mikeash.com/pyblog/friday-qa-2009-01-23.html

Upvotes: 0

tt.Kilew
tt.Kilew

Reputation: 6084

There's some possible options I see, when someone need to create class in runtime

  • To hide information about it (It won't help in most cases, but... you can)
  • To perform multiple-inheritance (If you really need it :)
  • Using your own language(i.e. some XML-like), that can be interpreted by your program, writted in Obj-C (Something like NSProxy, but even better.)
  • Creating some Dynamic-Class that can change it's behavior in runtime

In general.. There is some possible usages of this. But in real world, in default service applications there's no need to do this, actually:)

Upvotes: 6

Guillaume
Guillaume

Reputation: 4361

It could be used for example along Core Data or any API related to a database to create new classes of objects unknown at compilation time. However, I doubt this is used often, it's mostly the mechanism the system uses itself when it runs a program...

Upvotes: 0

Related Questions