I am at present engaged on flashcards app and have ecountered a difficulty with monitoring when the learning ought to cease. What I imply by that is that the present method would not depend when the final card was swiped. The logic is straightforward, when the consumer swipes final card within the “set”, he could be redirected to the EndView() the place he would see his statistics and will press restart button to review once more.
This is the code for the FlashcardSetView:
struct FlashcardSetView: View {
let units: FlashSets
@ObservedObject var dataController = DataController.shared
@State non-public var showTermDefinitionView = false
@Atmosphere(.managedObjectContext) var managedObjectContext
@Atmosphere(.dismiss) var dismiss
@State non-public var isTapped = false
@State non-public var isEdited = false
@State non-public var selectedCards: [FlashCardData] = [] // Maintain monitor of chosen playing cards
@State var allSwiped = false
var physique: some View {
NavigationView {
ZStack {
let playing cards = units.playing cards?.allObjects as? [FlashCardData] ?? []
ForEach(playing cards, id: .self) { card in
SingleFlashCard(card: card)
.onTapGesture {
if let index = selectedCards.firstIndex(of: card) {
selectedCards.take away(at: index)
} else {
selectedCards.append(card)
}
allSwiped = selectedCards.depend == 0
allSwiped = true
}
}
if (units.playing cards?.depend == 0) {
NavigationLink(vacation spot: EndView(), isActive: $allSwiped) {
EmptyView()
}
}
NavigationLink(vacation spot: EditFlashCardView(dataController: dataController, set: units), isActive: $isEdited) {
EmptyView()
}
}
}
.navigationBarItems(trailing:
Menu("Choices") {
Button(motion: {
showTermDefinitionView = true
}) {
NavigationLink(vacation spot: TermDefinitionView(currentSet: units), isActive: $showTermDefinitionView) {
Textual content("Add playing cards")
}
}
Button(motion: {
isEdited = true
}) {
Textual content("Edit playing cards")
}
}
)
HStack {
Button(motion: {
// Deal with button motion
}) {
Textual content("👍")
.body(width: 70, top: 50)
.background(Shade("Simple"))
.clipShape(RoundedRectangle(cornerRadius: 8))
}
.padding(.trailing, 20)
Button(motion: {
// Deal with button motion
}) {
Textual content("🤔")
.body(width: 70, top: 50)
.background(Shade("Assume"))
.clipShape(RoundedRectangle(cornerRadius: 8))
}
.padding(.trailing, 20)
Button(motion: {
// Deal with button motion
}) {
Textual content("🤬")
.body(width: 70, top: 50)
.background(Shade("Exhausting"))
.clipShape(RoundedRectangle(cornerRadius: 8))
}
.padding(.trailing, 20)
Button(motion: {
// Deal with button motion
}) {
Picture(systemName: "repeat.circle.fill")
.body(width: 70, top: 50)
.foregroundColor(.white)
.background(Shade.crimson)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
}
}
}