I am currently working on a SwiftUI project and encountering an issue with the .copyable(_:)
modifier. I want to copy the currently selected items in a List, and while using .copyable(_:)
works outside of navigation components, it doesn't seem to have any effect when used within NavigationSplitView
or NavigationStack
.
Has anyone successfully implemented copying functionality within a navigation structure using .copyable(_:)
?
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationSplitView {
List(0..<10) {
Text("row \($0)")
}
} detail: {
CopyableList()
}
}
}
struct CopyableList: View {
let strings = ["Alpha", "Beta", "Gamma"]
@State private var selection: Set<String> = []
var body: some View {
List(strings, id: \.self, selection: $selection) {
Text($0)
}
.copyable(Array(selection))
}
}