I going learn swift and swiftUI. I make application for organize notes by category. you can find my project in my GitHub if you need. https://github.com/yoan8306/List-Notes I have problem. I think it's simple. I would like make 2 alerts messages. The first it's when save is success and the second is when they are problem like one field is empty or category is empty.
private func checkNoteIsOk() -> Bool{
if !noteTitleField.isEmpty && !noteField.isEmpty && categorySelected != nil {
return true
} else {
return false
}
}
.
Button(action: {
guard checkNoteIsOk() else {
presentAlert = true
return
}
coreDM.saveNote(noteData: noteField, noteTitle: noteTitleField,
noteDate: Date(), noteCategory: categorySelected!)
emptyField()
saveSuccess = true
},
label: {
Text("Save")
}
)
}
//end Vstak
.navigationTitle("Create new note")
.alert(isPresented: $presentAlert) {
Alert(title: Text("Error !"), message: Text("Not saved"),
dismissButton: .default(Text("OK"))) }
.alert(isPresented: $saveSuccess) {
Alert(title: Text("Success !"), message: Text("Insert with success !"),
dismissButton: .default(Text("OK"))) }
I think it's because they are two alerts messages. And only the last message alert can display. Thank you for your answer and your help.
For multiple alerts in a single view, you can use an enum.
First, you need to create an enum like this and define all the alert message
now create one state var in the view.
and add the alert at the end
now show the alert by assigning the value. Like this