SwiftUI App Demo - Imtiaz211/interviews GitHub Wiki

SwiftUI Demo

@main
struct SampleApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}

@Main This property wrapper is declared to indicate that this struct is the entry execution point of the 
app(and starts the flow of the application). Somehow it’s a fancy way of saying that our app execution starts from this struct.

struct SampleApp: App This line indicates that this structs conforms to the App protocol and launches the app views.

var body: some Scene This “var body” is required so that the struct can conform to the App protocol. The body itself conforms to Scene protocol.
what is a “Scene”?:- A scene acts as a container for a view hierarchy that you want to display to the user.
WindowGroup:- This is a cross-platform struct that represents a scene of multiple windows. You can use it on macOS, iOS, etc.

struct ContentView: View {
    var myText: String
    
    init() {
        // Perform setup or initialization every thing here
        myText = "Welcome to SwiftUI!"
    }
    
    var body: some View {
        Text(myText)
        .onApper {
             // Code execute when view appears
           }
        .onDisappear {
          // code execute when view disappear
      }
    }
   deinit {
     // Perform cleanup or deallocation if necessary
   }
}