SwiftUI TextSelection crash on macOS

I have a very simple SwiftUI app, works fine on iOS, crashes on macOS:

struct ContentView: View { @State var testStr: String = "" @State var selection: TextSelection? = nil

var body: some View 
{
    VStack 
	{
		TextField("Test", text: $testStr, selection: $selection)  
		.onChange(of: selection) {print("selection changed")}
    }
    .padding()
}

} • Start app, write something in the TextField and move the cursor around. iOS: "selection changed" Mac: nothing (Bug ?)

• double click on some word both Mac and iOS: "selection changed"

• write some more in the TextField iOS: selection changed Mac: crash

Any idea what I am doing wrong?

Gerriet.

@Gerriet-1 What OS version and Xcode build is the issue reproducible on ?

Bug reproducible on macOS 15.0, Xcode: latest non beta at this time. macOS 15.1 Bug no longer reproducible. Xcode Version 16.1 (16B40).

SwiftUI TextSelection crash on macOS
 
 
Q