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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.