当前位置: 动力学知识库 > 问答 > 编程问答 >

Is the Objective-C Runtime API Available outside Darwin?

问题描述:

Objective-C has an amazing API for reading and changing its own runtime environment, but I can only find documentation for this API from Apple. Is the API only available on machines running a Darwin OS or is it actually part of Objective-C in general?

If its specific to Darwin is it at least available in the GNUstep framework?

Edit - What I'm Looking for Specifically

Specifically I am writing an XSD based serializer/deserializer and I would like to be able to create/modify class definitions based on XSD documents that are parsed during runtime, in order to make the framework more intuitive.

网友答案:

All the versions of Objective-C that I've seen have some facilities for mucking about with introspection and/or dynamic generation of classes at runtime.

The details will be different per different runtime and they may not all have feature parity (example; the apple runtime has blocks and that hasn't been ported everywhere).

网友答案:

Your updated question indicates you specifically wish to add/modify class definitions.

Following the reference Objective-C Compiler and Runtime FAQ mentioned above in the comments we find about libobjc2 which is part of GUNStep, and it’s runtime.h contains the method:

Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);

for creating classes - this appears to be the same as the one in Cocoa.

You might find Mike Ash's Creating Classes at Runtime in Objective-C helpful.

HTH

分享给朋友:
您可能感兴趣的文章:
随机阅读: