What to do when I deleted swift.main

I had a Swift 1.2 OS X document based (and CoreData FWTW) app, that when I updated to 2.0 gave me errors because in my swift.main there was a reference to two C_<something> variables which were not defined (I think they would have pointed to the old standby number of args and list of args argument that C main entry points had.)


I created a test document based Swift 2.0 app to see what the now approved format for swift.main, and I was surprised to see that there is no longer one created at all! Alrighty, I think, I'll just delete my swift.main and everything should be OK. Nope... Now I get a linker error...

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

So what SHOULD I put in my swift.main to make things OK, now?

Accepted Answer

What you really need is a call to NSApplicationMain. The normal way is to call it this way:


NSApplicationMain(Process.argc, Process.unsafeArgv)


You will also have to import AppKit or Cocoa.

You simply add @NSApplicationMain to your application delegate's file and not have a main file at all.

That works. I am curious, though, where this is documented, in particular the existence of the Process module namespace with those very useful variables. (Well not useful for a regular app, but for command line targets.) Are there other things squireled away worth knowing?

Here:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Reference/Swift_Process_Enumeration/index.html


Also cmd-click (or ctrl-cmd-J) on something (eg "Process" or "Swift") to open the generated interface for that module.

Thank you, thank you, thank you. It is good to see that the documentation is gradually getting filled in, including the "obvious" stuff.

Thank you. If I could mark two replies as "answering" the question, I would have done so with this one as well.

What to do when I deleted swift.main
 
 
Q