使用 main 方法复制类,就像在 Objective-C 和 Xcode 4 中的 Java IDE 中一样

发布于 2024-11-11 14:41:49 字数 276 浏览 2 评论 0原文

我有一个简单的问题。来自 java 背景,并且广泛使用 eclipse、netbeans 或任何其他 java IDE,能够向类添加 main 方法并在 IDE 中执行它,只需单击一下,然后查看输出,这真是太好了。

我一直在 xcode4/objective-c 中寻找相同的可能性,但我找不到方法。有时,我喜欢测试一小段软件,而不编译和运行整个项目。

由于我仍在 Java 中“思考”,您能否从“objective-c 开发人员的角度”建议使用 xcode4 实现此目的的正确方法?

谢谢

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/objective-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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2024-11-18 14:41:50

确实没有一种轻量级的方法可以做到这一点,但是我可以想到两种选择,具体取决于您是否想要保留您编写的线束代码。

如果这样做,那么您需要在项目中为您使用线束驱动的每个类创建一个新目标,并让该目标仅构建您正在驱动的类和一个仅包含 main 驱动该类的代码。

如果不这样做,那么您可以使用 main 创建一个目标,每次您想要驱动不同的类时,更改构建的文件,更改 main 中的代码代码>,然后重建。

这是假设您希望避免两者运行和编译其余代码。如果您不介意编译所有内容,则可以使用一个测试工具目标来构建所有类,并且可以动态更改 main 或使用 #ifdef s 或运行时参数来决定运行哪个帮助程序代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文