There is no main()
method in swift. The program must start the execution from somewhere. So what is the entry point of swift code execution and how is it decided?
The entry point in a plain Swift module is the file in the module called main.swift
. main.swift
is the only file which is allowed to have expressions and statements at the top level (all other Swift files in the module can only contain declarations).
Cocoa Touch uses the @UIApplicationMain
attribute on an implementation of UIApplicationDelegate
instead of a main.swift
file to mark the entry point. Cocoa used to use a minimal main.swift
file which simply called NSApplicationMain
, but as of Xcode 6.1 uses the @NSApplicationMain
attribute on an implementation of NSApplicationDelegate
.