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

SOLVED: Day 79 EditButton() Edit List Bug?

Forums > 100 Days of SwiftUI

Hello there everyone! I hope you're having a fabulous day!

I'm running into an issue with list editing. EditButton() and two finger swipe simulation is not working on a list in the simulator as described in Day 79 here:

https://www.hackingwithswift.com/books/ios-swiftui/letting-users-select-items-in-a-list

I'm using Xcode 15.3, iOS 17.4 simulator

Not sure if it's a problem on my end or not. This is the simple code I'm using from Paul:

struct ContentView: View {
    let users = ["Tohru", "Yuki", "Kyo", "Momiji"]
    @State private var selection: String?

    var body: some View {
        List(users, id: \.self, selection: $selection) { user in
            Text(user)
        }
        if let selection {
            Text("You selected \(selection)")
        }
        EditButton()
    }
}

   

You should use a Set instead of optional string for that to work. Paul exlpains it close to the end of the video.

struct ContentView: View {
    let users = ["Tohru", "Yuki", "Kyo", "Momiji"]
    @State private var selection = Set<String>() // This should be a Set

    var body: some View {
        List(users, id: \.self, selection: $selection) { user in
            Text(user)
        }
        if selection.isEmpty == false {
            Text("You selected \(selection.formatted())")
        }
        EditButton()
    }
}

   

OMG thank you... I had a feeling it was on my end.

   

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.