Can I create an Objective-C class at runtime from a text file?

Hi guys, so I have a strange question. I want to create Objective-C classes at runtime from a file. So, for example, I have an object application c, I then want to point it to a text file (or .hm pairs, no matter what works), and then ask the application to parse the text file and create a class at runtime (Class no object ) Of course, I would write a parser and all this, I just want to know if this is possible. I read these two articles:

http://www.mikeash.com/pyblog/friday-qa-2010-11-6-creating-classes-at-runtime-in-objective-c.html

http://www.mikeash.com/pyblog/friday-qa-2010-11-19-19-creating-classes-at-runtime-for-fun-and-profit.html

As shown, how to create a C object class at runtime, but its execution is performed using the C functions that were defined at compile time. If I can find a way to do the same, using strings to define functions that would be ideal, because then I don't need to define them at compile time.

+7
source share
3 answers

What is called reflexive programming. I think there is no support for evaluating code for Obj-C, since it is not a scripting language, so the concept of reflection for Obj-C is quietly limited. In addition, at runtime, the compiler already translates the code into clang Obj-C code, and it is a very time-consuming job to reverse-convert the bytecode and recompile it again

To reflect Obj-C you can refer to these answers

+2
source

Of course. Absolutely possible.

I suggest starting with Objective-C support in this , as it includes a complete Objective-C analyzer and code generator.

+1
source

see my github cocoa -interprreter project, it does part of what you want.

it takes a text file and compiles it at runtime .. and then runs the executable using NSTask. It would be easy to modify it so that the binary is loaded into a native process using NSBundle

https://github.com/Daij-Djan/cocoa-interpreter

+1
source

All Articles