
The App Delegate is a central class in an iOS app that handles the app’s lifecycle events such as launching, backgrounding, and termination.
The App Delegate is a central class in an iOS app that handles the app’s lifecycle events such as launching, backgrounding, and termination.
👉 File name: AppDelegate.swift
The sequence of states an app goes through:
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// App setup code
return true
}
| Method | Purpose |
|---|---|
didFinishLaunchingWithOptions |
Called when app launches |
applicationDidEnterBackground |
App goes to background |
applicationWillEnterForeground |
App returns to foreground |
applicationWillTerminate |
App is about to close |
Draw lifecycle flow:
Launch → Active → Background → Foreground → Terminated
func applicationDidEnterBackground(_ application: UIApplication) {
print("App in Background")
}
A View Controller manages a single screen. Adding new view controllers allows you to create multiple screens in your app.
Main.storyboardSecondViewController)Control + Drag from button → new view controller
Select:
let vc = storyboard?.instantiateViewController(withIdentifier: "SecondVC") as! SecondViewController
self.present(vc, animated: true)
vc.data = "Hello from First Screen"
Draw:
ViewController1 → (Button Click) → ViewController2
Screen 1:
Screen 2:
👉 On button click → navigate to screen 2
didFinishLaunchingWithOptions?didFinishLaunchingWithOptionsEach screen = one controller
Add via storyboard
Navigate using:
👉 Multi-screen apps require multiple view controllers
Open this section to view and download past papers
Click on Show Past Papers to load available exam papers.