I'm wondering if anyone else has experienced this behaviour? I'm running iOS 18 Beta 3 from Xcode 16 Beta 4 and encountering this:
struct MyView: View {
@State
private var selection: String?
let values: [String] = ["hello", "world"] // imagine these also have CLLocationCoordinates
var body: some View {
Map(selection: $selection) {
ForEach(values) { value in
Annotation(coordinate: value.coordinate) {
Text(value)
.tag(value)
}
}
}
.onChange(of: selection) {
print(selection)
}
}
When I run this sample code, and select say; the "hello" annotation, immediately followed by the "world" annotation, I will see this in the console:
nil // initial state
hello // tap "hello" annotation
nil // tap "world" annotation
world
when I would instead expect to see this:
nil // initial state
hello // tap "hello" annotation
world // tap "world" annotation
MapKit seems to add an extra "step" to the selection process where it momentarily clears the selection...
Is this expected behaviour?