10

If I create an Objective-C iOS application in Xcode, a file named main.m is generated. The contents of the file look something like this:

main.m

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

And this is where an Objective-C iOS application begins its life.

Importantly, if I want to subclass UIApplication (for whatever reason), then here is where I go to tell my app which class to use for the application class. Likewise, if for some reason I want to use a class name other than AppDelegate for my app, I'd change that information here.

HOWEVER, if I create a Swift iOS application in Xcode, no such file is generated (that I've been able to find). Where do I set these things up at?

Community
  • 1
  • 1
nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • Not a duplicate in the strict sense, but you should find it all here: [What does “@UIApplicationMain” mean?](http://stackoverflow.com/questions/24516250/what-does-uiapplicationmain-mean). – Martin R Apr 18 '15 at 20:50

1 Answers1

8

In Swift you can use the @UIApplicationMain attribute on your app delegate class, and it will automatically call the UIApplicationMain() function for you.

@UIApplicationMain
class YourAppDelegate: UIResponder, UIApplicationDelegate { ...

There's another option too:

If you do not use this attribute, supply a main.swift file with a main function that calls the UIApplicationMain function. For example, if your app uses a custom subclass of UIApplication as its principal class, call the UIApplicationMain function instead of using this attribute.


References:

Community
  • 1
  • 1
jtbandes
  • 115,675
  • 35
  • 233
  • 266