UIViewController – Lifecycle | Swift | viewDidLoad
UIViewController life cycle
viewdidload
viewwillappear
UIViewController เป็น subclass of ViewController, ก็จะมี inherite มาจาก class

และมี super. มาด้วย เป็นสิ่งที่ apple build on มาให้ด้วย

How to Navigate from one View Controller to another using Swift

from project

ViewControllerเป็น subclass of UIViewController เป็น base class forall view controller iOS
จากนั้น viewDidLoad ถูก call หลัง view controller’s view ถูก load เข้าสู่ memory
super.viewDidLoad() เป็นการ call parent class ของ viewDidLoad เพื่อให้แน่ใจว่า essential setup ถูกทำแล้ว

common customized

override func viewDidLoad() {
    super.viewDidLoad()
    
    let label = UILabel()
    label.text = "Hello, World!"
    label.textColor = .black
    label.center = view.center
    label.sizeToFit()
    view.addSubview(label)
}

helloworld Folder

  1. AppDelegate.swift
    • Manages app-level events and lifecycle transitions (e.g., app launch, backgrounding).
    • Responsible for setting up the app at launch.
  2. SceneDelegate.swift
    • Manages individual scenes in the app (introduced in iOS 13+).
    • Handles UI window setup and scene lifecycle events.
  3. ViewController.swift
    • The default view controller for the initial screen.
    • Contains the viewDidLoad() method, where you typically perform setup tasks.
  4. Main.storyboard
    • The main storyboard file containing UI elements for the app.
    • Visual interface editor for laying out views and controls.
  5. Assets.xcassets
    • Stores image assets, icons, and color sets.
    • Manages image assets used in the app.
  6. LaunchScreen.storyboard
    • Defines the launch screen (splash screen) displayed while the app is loading.
  7. Info.plist
    • A property list file containing configuration settings for the app (e.g., app name, permissions, supported orientations).

📁 helloworldTests Folder

  • helloworldTests.swift
    • Contains unit tests for the app’s functionality.
    • Used to verify that your app’s logic works as expected.

📁 helloworldUITests Folder

  • helloworldUITests.swift
    • Contains UI tests for the app’s interface.
    • Used to test user interactions and ensure the app’s UI behaves correctly.