On OSX, using a segmented picker style causes the following warning to be emitted (when a different selection is made) : "Publishing changes from within view updates is not allowed, this will cause undefined behavior." The warning is not emitted using the 'Preview Canvas' only when running the app.
Changing the picker style to automatic also fixes it, but the segmented style is used extensively.
Tested using XCode 26.4.1 on MacOS 26.3.1
--- view ---
import SwiftUI
internal import Combine
enum Mode : String {
case one, two, three
}
class MyObject : ObservableObject {
@Published var mode : Mode = .one
}
struct ContentView: View {
@StateObject var obj = MyObject()
var body: some View {
VStack {
Picker("Mode",selection: $obj.mode) {
Text("One").tag(Mode.one)
Text("Two").tag(Mode.two)
Text("Three").tag(Mode.three)
}
.pickerStyle(.segmented)
}
.padding()
}
}
#Preview {
ContentView()
}
--- app ---
import SwiftUI
@main
struct SwiftUIBugApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
0
0
8