开发者

Replicate class with main method as in Java IDE within Objective-C and Xcode 4

开发者 https://www.devze.com 2023-03-10 17:25 出处:网络
I have a simple question. Coming from a java background and having worked extensively with eclipse, netbeans or any other java IDE, is quite nice to have the possibility to add a main method to a clas

I have a simple question. Coming from a java background and having worked extensively with eclipse, netbeans or any other java IDE, is quite nice to have the possibility to add a main method to a class and execute it within the IDE, with just a click, and see the output.

I was looking for the same possibility within xcode4/o开发者_StackOverflowbjective-c but I couldn't find a way. From time to time, I like testing small piece of software, without compiling and running the whole project.

As I am still "thinking" in Java, could you suggest the proper way to achieve this with xcode4 from an "objective-c developer point of view" ?

thanks


There's not really a lightweight way to do this, but you have two options that I can think of depending on whether you want to keep the harness code you've written.

If you do, then you'd need to make a new target in your project for each class you drive with a harness, and have that target build just the class you are driving and a simple file with just the main code to drive that class.

If you don't, then you could make a target with a main, and each time you want to drive a different class, change which files are built, change the code in main, and rebuild.

This is assuming that you want to avoid both running and compiling the rest of your code. If you don't mind compiling everything, you could have one test-harness target that builds all of your classes, and either change main on the fly, or use #ifdefs or a runtime argument to decide which helper code to run.

0

精彩评论

暂无评论...
验证码 换一张
取 消