Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Counter shows an alert when it reaches 10.
import SwiftUI
struct AlertCounterView: View {
@State private var count: Int = 0
@State private var showAlert: Bool = false
var body: some View {
VStack(spacing: 20) {
Text("Counter: \(count)")
.font(.largeTitle)
HStack {
Button("+") {
count += 1
if count == 10 { showAlert = true }
}
Button("Reset") { count = 0 }
}
}.alert(isPresented: $showAlert) {
Alert(title: Text("Alert"), message: Text("Count reached 10!"), dismissButton: .default(Text("OK")))
}.padding()
}
}
@main
struct AlertCounterApp: App {
var body: some Scene {
WindowGroup {
AlertCounterView()
}
}
}SwiftUI is Apple’s declarative framework for building user interfaces across iOS, macOS, watchOS, and tvOS using Swift. It allows developers to create fully native apps with less code and real-time previews.
Origin & Creator
Created by Apple in 2019, SwiftUI was introduced to unify UI development across Apple platforms and replace UIKit/AppKit with a declarative approach.
Industrial Note
Perfect for Apple ecosystem apps where full native performance, Swift language, and declarative UI are priorities.