i had setup alert but alertResetSetting not showing, i do know why
but if change the positon
from:
.alert(isPresented: $showingIsResetSetting, content: alertResetSetting)
.alert(isPresented: $showingIsClearAll, content: alertClearAll)
to:
.alert(isPresented: $showingIsClearAll, content: alertClearAll)
.alert(isPresented: $showingIsResetSetting, content: alertResetSetting)
the alertResetSetting will be working but the alertClearAll not... why?
@State private var showingPrefixByCountry = false
@State private var showingIsResetSetting = false
@State private var showingIsClearAll = false
var body: some View {
VStack{
settingList
Spacer()
}
.padding(.top)
.alert(isPresented: $showingIsResetSetting, content: alertResetSetting)
.alert(isPresented: $showingIsClearAll, content: alertClearAll)
.alert("Select Your Country", isPresented: $showingPrefixByCountry) {
showingPrefixByCountryContent()
} message: { Text("Prefix")
.fontWeight(.light)
}
Section("Data") {
Button {
showingIsResetSetting.toggle()
} label: {
Spacer()
Text("Reset Setting")
.fontWeight(.semibold)
Spacer()
}
Button {
showingIsClearAll.toggle()
} label: {
Spacer()
Text("Clear All (Include history calls)")
.foregroundColor(Color.red)
.fontWeight(.bold)
Spacer()
}
}
private func alertResetSetting() -> Alert {
Alert(
title: Text("Are you sure you want to reset settings?"),
message: Text("This action will reset your settings. Without delete you history calls."),
primaryButton: .destructive(
Text("Reset"),
action: {
vm.resetSetting()
}
),
secondaryButton: .cancel(Text("Cancel"))
)
}
private func alertClearAll() -> Alert {
Alert(
title: Text("Are you sure you want to Clear All Data?"),
message: Text("This action will reset you setting and delete all history data"),
primaryButton: .destructive(
Text("Clear All"),
action: {
vm.clearAll()
}
),
secondaryButton: .cancel(Text("Cancel"))
)
}