Copyable doesn't work with NavigationSplitView

Problem

  • When copyable is used with NavigationSplitView then it doesn't work
  • The menu Edit > Copy is disabled

Note

When copyable is not used with a NavigationSplitView and used only with a plain List then it works.

Question

Is there anything I am missing?

Feedback

FB12990593

Platform

macOS 14.0 Beta (23A5312d) Xcode 15.0 beta 6 (15A5219j)

Steps to reproduce

  1. Run the app on mac
  2. Select some cars
  3. Press Command C

Expected Behaviour

  • Menu Edit > Copy should be enabled
  • Pressing Command C should allow user to copy selected cars

Actual Behaviour

  • Menu Edit > Copy is disabled
  • Pressing Command C doesn't allow user to copy selected cars

Code

struct ContentView: View {
    @State private var dataStore = DataStore()
    
    var body: some View {
        NavigationSplitView {
            Color.brown
        } detail: {
            CarListView(dataStore: dataStore)
        }
    }
}

struct CarListView: View {
    let dataStore: DataStore
    @State private var selectedCarIDs = Set<UUID>()

    var body: some View {
        List(selection: $selectedCarIDs) {
            ForEach(dataStore.cars) { car in
                CarCell(car: car)
                    .draggable(car)
            }
        }
        .copyable(selectedCars())
    }
    
    private func selectedCars() -> [Car] {
        dataStore.cars.filter { selectedCarIDs.contains($0.id) }
    }
}

struct CarCell: View {
    let car: Car
    var body: some View {
        VStack(alignment: .leading) {
            Text(car.name)
            Text("\(car.price)")
        }
    }
}

@Observable
class DataStore {
    var cars = [
        Car(name: "aaa", price: 10),
        Car(name: "bbb", price: 20),
        Car(name: "ccc", price: 30),
        Car(name: "ddd", price: 40)
    ]
}

struct Car: Codable, Transferable, Identifiable {
    let id: UUID
    let name: String
    let price: Int
    
    init(name: String, price: Int) {
        self.id = UUID()
        self.name = name
        self.price = price
    }
    
    static var transferRepresentation: some TransferRepresentation {
        CodableRepresentation(contentType: .car)
    }
}

extension UTType {
    static let car = UTType("com.example.car")!
}
Post not yet marked as solved Up vote post of newwbee Down vote post of newwbee
452 views

Replies

Hi. Do you already fix the problem? I have this problem too, and the beta is over now.