The @UIApplicationMain
attribute in Swift replaces the trivial main.m
file found in Objective-C projects (whose purpose is to implement the main
function that's the entry point for all C programs and call UIApplicationMain
to kick off the Cocoa Touch run loop and app infrastructure).
In Objective-C, the main (heh) bit of per-app configuration that the UIApplicationMain
function provides is designating one of your app's custom classes as the delegate of the shared UIApplication
object. In Swift, you can easily designate this class by adding the @UIApplicationMain
attribute to that class' declaration. (You can also still invoke the UIApplicationMain
function directly if you have reason to. In Swift you put that call in top-level code in a main.swift
file.)
@UIApplicationMain
is for iOS only. In OS X, the app delegate is traditionally set in the main nib file designated by the Info.plist (the same for Swift as for ObjC) — but with OS X storyboards there's no main nib file, so @NSApplicationMain
does the same thing there.