Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static method 'buildBlock' requires that 'Button<Any>.Type' conform to 'View'

Tags:

swiftui

New to swiftui. How do I solve this?


struct ContentView: View {
    var body: some View {
        HStack {
            VStack {
                Text("Hello World")
                .frame(maxWidth: .infinity, maxHeight: .infinity)
            }
            VStack {
                Button(action:  {
                    self.volumeCheck()
                }) {
                    Image("chimes")
                      .renderingMode(Image.TemplateRenderingMode?.init(Image.TemplateRenderingMode.original))

                }
                Button(action: {
                    self.volumeCheck()
                }) {
                    Text("Click chimes to test volume")
                }
            }
        }

    }

    func volumeCheck() {

    }
}


Report

static method 'buildBlock' requires that 'Button<Any>.Type' conform to 'View'

----------------------------------------

failedToBuildDylib: /Users/scottlydon/Library/Autosave Information/SmartWorkTimer/SmartWorkTimer/ContentView.swift:18:20: error: static method 'buildBlock' requires that 'Button<Any>.Type' conform to 'View'
            VStack {
                   ^
SwiftUI.ViewBuilder:3:24: note: where 'C1' = 'Button<Any>.Type'
    public static func buildBlock<C0, C1>(_ c0: C0, _ c1: C1) -> TupleView<(C0, C1)> where C0 : View, C1 : View
                       ^
/Users/scottlydon/Library/Autosave Information/SmartWorkTimer/SmartWorkTimer/ContentView.swift:26:17: error: generic parameter 'Label' could not be inferred
                Button
                ^
/Users/scottlydon/Library/Autosave Information/SmartWorkTimer/SmartWorkTimer/ContentView.swift:26:17: note: explicitly specify the generic arguments to fix this issue
                Button
                ^
                      <<#Label: View#>>

like image 644
ScottyBlades Avatar asked Nov 16 '22 00:11

ScottyBlades


1 Answers

I've met this same bug (Static method 'buildBlock' requires that 'Button' conform to 'View') with Xcode 13.1. Not with all projects, just with some. Amazingly what helped me is to use Button the following way (just prefixed with SwiftUI):

SwiftUI.Button

like image 121
t1ser Avatar answered Jun 22 '23 01:06

t1ser