I want an alert to be displayed when the user is moved to a new page without any action and quickly I use NavigationLink
ContentView.swift
struct ContentView: View {
var body: some View {
VStack{
NavigationLink(destination: SecondView()){
Text("Go to second view")
}
}
}
}
SecondView.swift
struct SecondView: View {
@State var showAlert = true
var body: some View {
// i want to show alert when navigate to this view
VStack{
Text("Second View")
.alert(isPresented: $showAlert) {
Alert(title: Text("You are in second view"))
}
}
}
}
you can help me ?
2
Answers
Change
showAlert
value to true whenVStack
appeared , like thatNow here we are going to show alert using the APAlert class
Reference :-
https://github.com/Arvindcs/APAlertView