Learn Courses My Dashboard

Error instantiating a button in xcode 13

I’m viewing the Apple App swift development course by CodewithChris. I am using Xocde 13.2.1 for swift but the video instruction is for Xcode 12. I found the error;

Cannot convert value of type ‘(() → Void).Type’ to expected argument type ‘() → Void’

this error happens on the line with " Button(“Click Me”, action: ()-> Void) "

I could not figure this error out but I suspect a different version of Swift and or xcode as my source code is exactly the same as Chris’s.

What causes this error?


//
//  ContentView.swift
//  ButtonDemoApp
//
//  Created by Jon on 12/27/21.
//

import SwiftUI

struct ContentView: View {
    var body: some View {
 
        Button("Click Me", action: ()-> Void)
        
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

()-> Void is just a placeholder and should be highlighted. You can just press enter to get a more workable code instead. If not, it should be

Button("Click me", action: { 
// code goes here
})