0

What will be the result when I delete AppDelegate from project?

What's the use of AppDelegate in iOS project?

Is AppDelegate causes increase in memory size of .app?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gowtham
  • 385
  • 1
  • 11
  • 4
    Possible duplicate of [What is the AppDelegate for and how do I know when to use it?](https://stackoverflow.com/questions/652460/what-is-the-appdelegate-for-and-how-do-i-know-when-to-use-it) – Ashish Kakkad Jul 13 '17 at 05:04
  • The appDelegate is also an important class in iOS App design. If you facing increase in memory size then please check and debug for what reasons these are Occuring – Gourav Joshi Jul 13 '17 at 05:05
  • You can delete it and try what gonna happen, and when you need a new one, just add it back to your project from the trash, or let Xcode generate new one for you. – Ennabah Jul 13 '17 at 05:05
  • yeah it does increase the memory size slightly but it's worth it!!!! teehee – Nerdy Bunz Feb 13 '18 at 11:08

3 Answers3

3

The entry point for every C-based app is The Main Function and iOS apps are no different. What is different is that for iOS apps you do not write the main function yourself. Instead, Xcode creates this function as part of your basic project. With few exceptions, you should never change the implementation of the main function that Xcode provides.

The main function of an iOS app

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

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

The UIApplicationMain function ,hands control off to the UIKit framework , by creating the core objects of your app, loading your app’s user interface from the available storyboard files, calling your custom code so that you have a chance to do some initial setup, and putting the app’s run loop in motion.

The app delegate is the heart of your custom code. This object works in tandem with the UIApplication object to handle app initialization, state transitions, and many high-level app events. This object is also the only one guaranteed to be present in every app, so it is often used to set up the app’s initial data structures.

Hence if we delete AppDelegate file from Xcode Project all above processes will be cease and hence app would not launch.

Check apple developer site for more info on App Life Cycle.

luckyShubhra
  • 2,731
  • 1
  • 12
  • 19
  • Much better explained :) Hence +1 – Sandeep Bhandari Jul 13 '17 at 05:43
  • Thanks @SandeepBhandari m trying !! – luckyShubhra Jul 13 '17 at 05:52
  • @luckyShubhra Where i can see UIApplicationMain function explanation in XCode project? – Pradeep Singh Apr 18 '21 at 13:24
  • 1
    @PradeepSingh In Swift 5.3 there is a new "@main" attribute which lets you control where your entry point is in your project rather than just main.swift. There can only be one main entry and you can't have a main.swift file and a an attribute "@main". See https://github.com/apple/swift-evolution/blob/master/proposals/0281-main-attribute.md for more details. – luckyShubhra May 04 '21 at 10:32
1

No you can't delete App-Delegate file, Its generated by X Code on project creation.Once you delete it this will not allow you to run your app.

There is no size increase by this App-Delegate file

sugansoft
  • 1,227
  • 8
  • 26
0

You cant't run application without AppDelegate

Launch time is an important point in an app’s life cycle. At launch time, the app delegate is responsible for executing any custom code required to initialize your app. For example, the app delegate typically creates the app’s initial data structures, registers for any required services, and tweaks the app’s initial user interface based on any available data. Apple Doc

KKRocks
  • 8,222
  • 1
  • 18
  • 84