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

Solved: Day 88 - Extra trailing closure passed in call

Forums > 100 Days of SwiftUI

I am about to complete day 88, but I am getting an error in the last step (Extra trailing closure passed in call) when I add the "withAnimation" at the CardView, code below. I am using XCode 13.1.

struct ContentView: View {

    @State private var cards = [Card](repeating: Card.example, count: 10)

    var body: some View {
        ZStack {
            Image("background")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)
            VStack {
                ZStack {
                    ForEach(0..<cards.count, id: \.self) { index in
                        CardView(card: self.cards[index]) {
                            withAnimation {
                                self.removeCard(at: index)
                            }
                        }
                        .stacked(at: index, in: self.cards.count)
                    }
                }
            }
        }
    }

    func removeCard(at index: Int) {
        cards.remove(at: index)
    }
}

Thanks a lot.

3      

I assume in your CardView you have this

let card: Card
var removal: (() -> Void)? = nil

I have put your ZStack in my project and it works fine, so your error is somewhere else.

This is my from same project for your reference.

ZStack {
    ForEach(0..<cards.count, id: \.self) { index in
        CardView(card: cards[index]) {
            withAnimation {
                removeCard(at: index)
            }
        }
        .stacked(at: index, in: cards.count)
        .allowsHitTesting(index == cards.count - 1)
        .accessibility(hidden: index < cards.count - 1)
    }
}
.accessibility(addTraits: .isButton)
.allowsHitTesting(timeRemaining > 0)

PS your no longer need the self. even though it in the videos. This was updated from Xcode 13

3      

Thanks @NigelGee and @Obelix ! Found the issue.

I had removal as a let instead of a var.

Thanks again!

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.