Skip to content

Instantly share code, notes, and snippets.

@ben221199
Last active September 10, 2022 11:37
Show Gist options
  • Save ben221199/68aaa1a9dbb19878b9b71248d28c3f8e to your computer and use it in GitHub Desktop.
Save ben221199/68aaa1a9dbb19878b9b71248d28c3f8e to your computer and use it in GitHub Desktop.

Apple Application Startup

iOS

Write main function and call UIApplicationMain

Objective-C

#import <UIKit/UIKit.h>

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

Swift

import UIKit

UIApplicationMain(CommandLine.argc,CommandLine.unsafeArgv,nil,NSStringFromClass(AppDelegate.self))

Write AppDelegate class with @UIApplicationMain attribute

The @UIApplicationMain attribute orders to generate a main function that calls the UIApplicationMain function with the current class as parameter.

Objective-C

Not supported. Write the main function manually.

Swift

@UIApplicationMain
class AppDelegate : UIResponder,UIApplicationDelegate{

}

Write AppDelegate class with @main attribute

The @main attribute orders to make the static main function inside the current class the entry of the application. Because UIApplicationDelegate already implements such main function, nothing more is needed.

Objective-C

Not supported. Write the main function manually.

Swift

Since Swift 5.7

@main
class AppDelegate : UIResponder,UIApplicationDelegate{

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment