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()
}
}
}
You are correct, changed that to macOS and I see the warning: Publishing changes from within view updates is not allowed, this will cause undefined behavior.
Please file a bug for that. Once you open the bug report, please post the FB number here for my reference.
If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?
Albert Worldwide Developer Relations.