Single quotes around IBAction

2019-03-05 10:15发布

问题:

I have a button to create an IBAction, and that button is Continue. However, when attaching the action I want to have a lower case continue. For some reason when I attach the action it is surrounded by single quotes. Why is this the case?

@IBAction func `continue`() {
  //
}

回答1:

continue is a swift keyword (along with many other programming languages) and as such cannot be used for variable's or action names without being wrapped in backtick quotes.

The compiler wraps it in backtick quotes as to not compute it as the keyword continue

Apple Doc