简体   繁体   中英

Launch sequence of Swift app

Any one knows the launch sequence of a swift app?. As i can see there is no main function in a swift application. Then who is responsible for doing this

// Entry point of a normal iOS app
int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Your application object and AppDelegate is getting created here. But for swift app i was wondering who is creating these.

If any one knows, share your thoughts.

If you look at AppDelegate.Swift class, you will find the @UIApplicationMain statement written in the global area of the file. As @Daniel also mention in his answer.

Now I tried commenting that line and compiling the code, look what I got..

在此输入图像描述

In very simple language, error say compiler trying to search implicit entry/start for main executable , but not getting.

it shows @UIApplicationMain statement in AppDelegate.Swift creates a implicit entry point for Swift program.

And I tried to write main.swift class explicitly...it works.

my main.swift looks like..

import Foundation
import UIKit

UIApplicationMain(C_ARGC, C_ARGV, NSStringFromClass(UIApplication), NSStringFromClass(AppDelegate))

the swift Book says:

Code written at global scope is used as the entry point for the program, so you don't need a main function.

If you have a look at your AppDelegate there is a marker @UIApplicationMain which is outside of any scope and considered as entry point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM