0

I am writing a document-driven Cocoa app for which I want to create a special "command-line mode" which will not launch any windows and requires no user interaction.

This thread from 2010 asks the same question, but for older Cocoa projects that included a main.m file. Is it possible to do this for a modern Cocoa app that uses only Swift and thus does not have a main.m?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
todd412
  • 1,308
  • 2
  • 17
  • 24
  • 3
    A Swift app can certainly have a _main_ file. – matt Jan 28 '19 at 04:43
  • @matt a new project created in Xcode 10.1 that uses Swift does not come with a main.m file. Are you suggesting that adding a main.m file to such a project is a good way to accomplish this? – todd412 Jan 28 '19 at 18:41

1 Answers1

1

Yes. In Xcode select File > New > Target > Command Line Tool and select Swift as the language. This will add main.swift in a separate target that you can bundle with your app.

pointum
  • 2,987
  • 24
  • 31