Post

Replies

Boosts

Views

Activity

How to create swipeActions for a multi-level list?
How do I create swipeActions for a multi-level (recursive) list? With a simple list I can do this, and everything works just fine: struct ContentView: View { @State private var data = ["One", "Two", "Three"]     var body: some View {         List(data, id: \.self) { item in             Text(item)                 .swipeActions(edge: .trailing, allowsFullSwipe: true) {                      Button("Delete", role: .destructive) {                          data.removeAll { $0 == item }                      }                  }         }     } } But when I try the same with a multi-level list, I cannot swipe any of its rows (nothing happens when I try to swipe): struct MyData: Hashable {     let value: String     var children: [MyData]? = nil } struct ContentView: View {     @State private var data: [MyData] = [         .init(             value: "One",             children: [                 .init(value: "Two"),                 .init(                     value: "Three",                     children: [                         .init(value: "Four"),                         .init(value: "Five")                     ]                 )             ]         )     ]     var body: some View {         List(data, id: \.self, children: \.children) { item in             Text(item.value)                 .swipeActions(edge: .trailing, allowsFullSwipe: true) {                     Button("Delete", role: .destructive) {                         data.removeAll { $0 == item }                     }                 }         }     } } How to make this work?
0
0
328
Dec ’22
Question re. sharing Core Data with CloudKit
I have a very basic question: when I share a Core Data object with another user via ClodKit and let's say do it via a message, when the user who receives the message clicks on the link, how does their device know which app should be used to read this object?
Replies
2
Boosts
0
Views
753
Activity
Mar ’23
How to create swipeActions for a multi-level list?
How do I create swipeActions for a multi-level (recursive) list? With a simple list I can do this, and everything works just fine: struct ContentView: View { @State private var data = ["One", "Two", "Three"]     var body: some View {         List(data, id: \.self) { item in             Text(item)                 .swipeActions(edge: .trailing, allowsFullSwipe: true) {                      Button("Delete", role: .destructive) {                          data.removeAll { $0 == item }                      }                  }         }     } } But when I try the same with a multi-level list, I cannot swipe any of its rows (nothing happens when I try to swipe): struct MyData: Hashable {     let value: String     var children: [MyData]? = nil } struct ContentView: View {     @State private var data: [MyData] = [         .init(             value: "One",             children: [                 .init(value: "Two"),                 .init(                     value: "Three",                     children: [                         .init(value: "Four"),                         .init(value: "Five")                     ]                 )             ]         )     ]     var body: some View {         List(data, id: \.self, children: \.children) { item in             Text(item.value)                 .swipeActions(edge: .trailing, allowsFullSwipe: true) {                     Button("Delete", role: .destructive) {                         data.removeAll { $0 == item }                     }                 }         }     } } How to make this work?
Replies
0
Boosts
0
Views
328
Activity
Dec ’22