Search code examples
swiftwatchkit

watch button press crash


it seems to be the same error and conditions as this unanswered SO question, but I have more to add (its really easy to replicate)

Create a new project in the latest Xcode

iOS App with WatchKit App

Go to the WatchKit App > Interface.storyboard and put a single button on the Interface Controller Scene > Interface Controller enter image description here

Go to WatchKit Extension > InterfaceController.swift and add a new member

@IBOutlet var scheduleMeetingButton: WKInterfaceButton!

and method

@IBAction func scheduleMeeting(_ sender: Any) { }

then go back to Interface.storyboard and link both of these to the button

launch the app (on the watch simulator) enter image description here

than click the button and you will get this exec error

enter image description here

What is causing this error?


Solution

  • From looking at your code i would suggest updating the action function from sender: any to sender: wkinterfacebutton hope this helps!