具有可选命令行模式的Cocoa应用程序 [英] Cocoa application with an optional command line mode

查看:48
本文介绍了具有可选命令行模式的Cocoa应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要从头开始一个新的Cocoa项目,已经获得的要求之一是能够从同一可执行文件中选择Cocoa GUI或命令行模式.将来可能会增加脚本编写能力,但现在不成问题了.

I'm about to start a new Cocoa project from scratch and one of the requirements I have already been given is being able to choose either a Cocoa GUI or a command line mode from the same executable. Scriptability may be a possible addition in the future but that is not a concern right now.

在Cocoa中解决此问题的最佳策略是什么,特别是如果我想维护Obj-C垃圾收集等某些Cocoa功能时?

What is the best strategy for going about this in Cocoa, especially if I want to maintain certain Cocoa features like Obj-C garbage collection?

推荐答案

Xcode会使用带有命令行参数的main函数为您生成main.m.您应该解析它们,并且如果需要保持命令行模式,则永远不要启动应用程序.如果您是GUI,则可以正常启动.

Xcode will generate a main.m for you with a main function that has the command line arguments. You should parse them and if you need to stay in command-line mode, never do the application startup. If you are being a GUI, just start normally.

这篇关于具有可选命令行模式的Cocoa应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆