WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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 )
    }
}

1      

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!

1      

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

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

Reply to this topic…

You need to create an account or log in to reply.

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.