Post

Replies

Boosts

Views

Activity

Reply to List with EditButton for selection, delete, and move
I think so, but I'm not sure exactly what you're trying to do. Here, I copied the code from the documentation for EditButton, and added some ability to select by tapping the text. (Probably you want to render the selection in a different way, not just green text, but I did that for simplicity.) struct ContentView: View {     @State private var fruits = [         "Apple",         "Banana",         "Papaya",         "Mango"     ]     @State private var selected = Set<String>()     var body: some View {         NavigationView{             List {                 ForEach(fruits, id: \.self) { fruit in                     Text(fruit)                         .foregroundColor( selected.contains(fruit) ? Color.green : nil )                         .onTapGesture { toggleSelected(fruit) }                 }                 .onDelete { self.deleteFruit(at :$0) }                 .onMove { self.moveFruit(from: $0, to: $1) }             }             .navigationTitle("Fruits")             .toolbar { EditButton() }         }     }     func toggleSelected(_ fruit: String) {         if selected.contains(fruit) { selected.remove(fruit) }         else { selected.insert(fruit) }     }     func deleteFruit(at: IndexSet) { fruits.remove(atOffsets: at) }     func moveFruit(from: IndexSet, to: Int) { fruits.move(fromOffsets: from, toOffset: to) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to Massive Memory Leak in SwiftUI for macOS
I just pasted your code into Xcode, ran it, and started clicking around. It seems a bit bogged down, because it can take over a second to change the VeryComplexView when I click on the different numbers in the left nav. But, the memory use is staying around 100-150MB. I'm running macOS 11.2.3, so maybe you could try upgrading to that?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Differentiating between "return" and focus loss in TextField onCommit
Sorry, I don't follow. There is no action: parameter for TextField, so what is would get triggered by the keyboard shortcut? I tried putting the modifier on it anyway, but the behavior is the same. TextField("Search", text: $searchQuery) { editing in .... } onCommit: { ... // still triggered by return OR focus loss }.keyboardShortcut(.defaultAction) I ended up using NSViewRepresentable and wrapping an NSTextField. So I have something working now, but I'd prefer to use pure SwiftUI if I can.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21