小编Fit*_*syu的帖子

什么`_?`在Swift中意味着什么?

几天前,我将旧的Xcode 8项目转换为Xcode 9中的Swift 4.我注意到在代码上方生成了额外的Swift代码以及解释.

这是它的样子:

// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
// Consider refactoring the code to use the non-optional operators.
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}
Run Code Online (Sandbox Code Playgroud)

我试图理解代码的作用,并在代码中找到我认为有点不寻常_?的东西.

我猜它是未使用的可选项,因为这_意味着我们不会使用特定的变量,因此我们不关心变量的名称,?而是可选的语法.

谢谢您的帮助!

swift

3
推荐指数
1
解决办法
502
查看次数

标签 统计

swift ×1