UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 91: Flashzilla challenge 2 & 3

Forums > 100 Days of SwiftUI

Hi! I'm stuck on the challenge 2 of Flashzilla. I tried the solutions from this thread (https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-91-flashzilla-challenges-can-t-seem-to-readd-a-card-successfully/2037) but even though the cards get readded to the beginning of the array I can't see them appearing and the game doesn't finish (readded cards don't show so the screen is left empty with running timer). I will be grateful for any advice. Also I don't really understand what should I do in challenge 3- anyone could give me a hint?

result is either "correct" or "wrong". I pass it from the CardView to the removeCard function through the removal function. reuseQuestions is a Boolean that the user is setting wether to reuse cards or not.

    func removeCard(at index: Int, result: String) {
        guard index >= 0 else { return }

        if (reuseQuestions && result == "wrong") {
            let tempCard = cards.remove(at: index)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
              cards.insert(tempCard, at: 0)
            }
        } else {
            cards.remove(at: index)
        }
        if cards.isEmpty {
            self.isActive = false
        }
    }
ZStack {
    ForEach(cards, id: \.self) { card in
        CardView(card: card) { result in
            withAnimation(Animation.linear.delay(0.6)) {
                let index = self.cards.firstIndex(of: card)!
                self.removeCard(at: index, result: result)
             }
         }
         .stacked(at: self.cards.firstIndex(of: card)!, in: self.cards.count)
         .allowsHitTesting(self.cards.firstIndex(of: card)! == self.cards.count - 1)
         .accessibility(hidden: self.cards.firstIndex(of: card)! < self.cards.count - 1 )
    }
}

3      

I figure you solved this already but just in case it can be helpful to someone else, here is a hint for the third challenge:

In CardView, change the > in the .fill modifier by a >= like this:

.fill(offset.width >= 0 ? Color.green : Color.red)

That'll give you exactly the opposite problem, and hopefully a clue on how to fix it.

Hope that helps!

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.