Component

Alerts

Learn to add Alerts to your iOS App (Supports Xcode 16 and iOS 18)

Alerts

Just copy the below code and modify according to your needs.

import SwiftUI

struct ContentView: View {
    @State private var showAlert = false // State variable to control alert visibility

    var body: some View {
        VStack {
            Button("Show Alert") {
                showAlert.toggle() // Toggle alert visibility
            }
            .alert(isPresented: $showAlert) { // Present the alert when showAlert is true
                Alert(
                    title: Text("Alert Title"), // Title of the alert
                    message: Text("This is an alert message."), // Message to display
                    primaryButton: .default(Text("Confirm")) {
                        // Action to perform on Confirm
                        print("Confirmed!")
                    },
                    secondaryButton: .cancel() // Action to perform on Cancel
                )
            }
        }
        .padding()
    }
}

Time to build your iOS App?

ShipiOS provides you SwiftUI boilerplate, How-to Guides, Components Library and extra rewards!

Get ShipiOS Package
ShipiOS.App

I told you it's more than just a boilerplate :)

Made with ❤️ on 🌍

Need help? Reach out on:

© Copyright 2024 ShipiOS.App - All rights reserved.