Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does a Swift iOS application begin its life?

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?

like image 809
nhgrif Avatar asked Apr 18 '15 20:04

nhgrif


People also ask

What is the life cycle of the iOS application?

The application life cycle constitutes the sequence of events that occurs between the launch and termination of application. It is very important to understand for all the iOS Developers, who wants smooth user experience.

What is app life cycle in Swift iOS?

Every iOS application passes through the following states as it runs. Not Running: the app is considered to be in a Not Running state when it is not yet launched or terminated by the system or user. Inactive: the app is in an inactive state when it is in the foreground but receiving events.

What is the life cycle of an app?

Typically, application lifecycle management characterizes itself in six stages: development, introduction, growth, maturity, saturation, and decline. The duration of these stages fully depends on the product or application itself, the complexity, and the fit in the market.

How many states are in iOS life cycle?

An iOS app lifecycle involves each state a mobile app goes through between launch and termination. The five states include not running, inactive, active, background, and suspended.


1 Answers

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:

  • The Swift Programming Language: Attributes
  • What does "@UIApplicationMain" mean?
like image 173
jtbandes Avatar answered Nov 16 '22 11:11

jtbandes