How to call some view function in alert in swift
I have created this function for showing some data in alert(not in sheet or popover).how can I call this message in alert in swiftUI and please create if any extensions neededenter image description here
but I want to show that content in alert private func popUpView() -> some View {
VStack(alignment: .center) {
let correctAnswers = selectedQuestions.filter { question in
question.answerJSON.contains { answer in
answer.ans?.first?.t == question.userAnswer
}
}
let totalQuestions = selectedQuestions.count
let totalAnsweredQuestions = selectedQuestions.filter { $0.isAnswered }.count
let wrongAnswers = totalAnsweredQuestions - correctAnswers.count
let unansweredQuestions = totalQuestions - totalAnsweredQuestions
VStack(alignment: .leading){
HStack(alignment: .center){
Circle()
.foregroundColor(
Color(red: 194/255, green: 231/255, blue: 255/255, opacity: 1)
)
.frame(width: 30, height: 30, alignment: .leading)
.overlay(
Image("ic_Clock")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 15, height: 15)
)
Text("Total Questions")
.padding(.leading, 20)
Spacer()
Text(String(totalQuestions))
.foregroundColor(Color.blue)
.padding(.trailing, 10)
}
.padding(10)
Divider().background(Color.gray)
.shadow(radius: 0.5)
HStack(alignment: .center) {
Circle()
.foregroundColor(Color(red: 194/255, green: 231/255, blue: 255/255, opacity: 1))
.frame(width: 30, height: 30, alignment: .leading)
.overlay(
Image("ic_Clock")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 15, height: 15)
)
Text("Correct Answer")
.padding(.leading, 20)
Spacer()
Text(String(correctAnswers.count))
.foregroundColor(Color.blue)
.padding(.trailing, 10)
}
.padding(10)
Divider().background(Color.gray)
.shadow(radius: 0.5)
HStack(alignment: .center) {
Circle()
.foregroundColor(Color(red: 194/255, green: 231/255, blue: 255/255, opacity: 1))
.frame(width: 30, height: 30, alignment: .leading)
.overlay(
Image("ic_Clock")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 15, height: 15)
)
Text("Wrong Answer")
.padding(.leading, 20)
Spacer()
Text(String(wrongAnswers))
.foregroundColor(Color.blue)
.padding(.trailing, 10)
}
.padding(10)
Divider().background(Color.gray)
.shadow(radius: 0.5)
HStack(alignment: .center) {
Circle()
.foregroundColor(Color(red: 194/255, green: 231/255, blue: 255/255, opacity: 1))
.frame(width: 30, height: 30, alignment: .leading)
.overlay(
Image("ic_Clock")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 15, height: 15)
)
Text("Unanswered")
.padding(.leading, 20)
Spacer()
Text(String(unansweredQuestions))
.foregroundColor(Color.blue)
.padding(.trailing, 10)
}
.padding(10)
}
Divider().background(Color.gray)
.shadow(radius: 0.5)
Text("Do you Want to Submit the test?")
.font(Font.custom("avenir_bold", size: 14).bold())
.padding(10)
HStack(alignment: .center) {
Button(action: {
withAnimation {
self.showPopUp = false
}
}) {
Text("Close")
.modifier(CustomTextM(fontName: "avenir_bold", fontSize: 14, fontColor: Color.blue))
.frame(maxWidth: .infinity, maxHeight: 40)
.background(Color.white)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.blue, lineWidth: 1)
)
}
Spacer(minLength: 20)
Button(action: {
withAnimation {
navigationSelection = 1
self.showPopUp = false
}
eventTest.endTest()
navigateToHome = true
}) {
Text("Submit")
.modifier(CustomTextM(fontName: "avenir_bold", fontSize: 14, fontColor: Color.white))
.frame(maxWidth: .infinity, maxHeight: 40)
.background(Color.blue)
.cornerRadius(20)
}
.background(
NavigationLink(destination: HomeView(), isActive: $navigateToHome) { EmptyView() }
)
}
}
}