Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch sequence of Swift app

Tags:

ios

swift

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.

like image 440
Anil Varghese Avatar asked Jun 06 '14 05:06

Anil Varghese


1 Answers

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..

enter image description here

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))
like image 176
Suryakant Sharma Avatar answered Nov 02 '22 13:11

Suryakant Sharma