“在swift中是什么意思,为什么它有用?

下面的代码中的 `` 默认值是什么意思?

你想在什么情况下使用它?

static let `default` = User(id: UUID(), name: "Anonymous")

提前谢谢

回答

反引号允许您在无法使用的地方使用受限制的关键字,例如变量名。

default 在 Swift 中是一个受限制的关键字,但是通过在它周围加上反引号,它就变成了一个有效的变量名。

如果没有反引号,您的代码将导致错误

关键字“default”不能用作此处的标识符

  • This is the correct answer. However, I would advise against using restricted keywords in this way. It's confusing and makes your code harder to follow. I know about this language feature, but end up spending an embarrassing amount of time staring at code trying to figure out what the heck it's doing on those rare occasions when I encounter it.

以上是“在swift中是什么意思,为什么它有用?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>