Xcode 16: SwiftUI plain Button & UIButton not working

It looks like Xcode 16 has changed this behavior so I'm not sure if this is a bug or not.

When a SwiftUI Button wraps a UIButton, the button doesn't work on iOS 18.0+

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Button(action: {
                print("Not called on iOS 18")
            }) {
                WrapperButton()
                    .frame(width: 200, height: 50)
            }
        }
    }
}

struct WrapperButton: UIViewRepresentable {

    func makeUIView(context: Context) -> some UIView {
        let button = UIButton(type: .system)
        button.setTitle("OK", for: .normal)
        return button
    }

    func updateUIView(_ uiView: UIViewType, context: Context) {}
}

This occurs with the app build with Xcode 16 and running on iOS 18 but it was worked with Xcode 15 builds and running on iOS 18

Do you get the same results with just the relevant code in a small test project? If so, please share a link to your test project. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project

Albert Pascual
  Worldwide Developer Relations.

Xcode 16: SwiftUI plain Button & UIButton not working
 
 
Q