0

I Want to generate A simple "Hello World" objective-C program, Which API i have to use for that? Really I don't know is it possible or not?, but in java I know there is CodeModel API.

JCodeModel cm = new JCodeModel();
JDefinedClass class1 = cm._class("Main");
JMethod method = class1.method(JMod.PUBLIC, cm.VOID, "print");
JBlock block = method.body();
JVar a = block.decl(cm.INT, "a", JExpr.lit(10));
JVar b = block.decl(cm.INT, "b", JExpr.lit(20));

with use of this code we create one file with class name as "main", method name is "print" and in method body is "a & b two int variables", like that i want to create one file in objective-C for displaying "Hello world" in view. is it possible?, if yes, How can?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Just to clarify - you want to create the Obj-C program at run-time? – Peter Hull May 18 '13 at 10:24
  • @peter Hull, yes, I want like that. – kishore reddy May 18 '13 at 10:32
  • Why? What are you actually trying to achieve? Are you just experimenting? – Wain May 18 '13 at 10:40
  • No, i am fresher, i had joined recently in one company, thy are given task to generate code for display "Hello world" in view with use of another program. – kishore reddy May 18 '13 at 10:45
  • There isn't an equivalent of CodeModel API. If you want to generate code at runtime your application will be rejected by Apple. You can create classes and attach existing code as new methods, but not really create code generating bytecode. – Jano May 18 '13 at 11:18
  • I don't know exactly, but XCDataModel is seems to useful for this, please provide me some brief explanation about "Core Data" and "XCData Model". – kishore reddy May 18 '13 at 11:28
  • 1
    xcdatamodel is related to Core Data - which is used for the persistence layer, and isn't relevant to what you are asking about. – Abizern May 18 '13 at 13:08
  • Do you want to generate *source code*, or *an executable*? – sigpwned May 18 '13 at 16:08

1 Answers1

1

What you are asking to do is very difficult in OS X and nigh impossible for iOS.

Unlike Java, which uses bytecode to store programs, Objective-C is compiled into a native executable. This means you would need a full compiler and linker built into your application.

Needless to auto-generating OS X executables is very difficult.

Once you have compiled and linked the executable you've created, then you need to execute it. In OS X you can directly execute binares, but all binaries in iOS must be digitally signed by Apple. The executable would need to be packaged up as a new App and signed by your distribution profile. The new App would need to be submitted to Apple to be digitally signed. It would then need to be downloaded and installed from Apple. Finally, it could be executed as a separate App.

To my knowledge, Apple has no program for receiving auto-generated programs. I don't think Apple has any interest in this as a business model and working it out with Apple would involve lots of lawyers and contracts that I would never hope to understand.

Needless to say auto-generating iOS executables is nigh impossible.

Perhaps it would be easier to look into other alternatives.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117