【问题标题】:Swift compiler error: missing argument labels [duplicate]Swift 编译器错误:缺少参数标签 [重复]
【发布时间】:2017-08-05 21:54:28
【问题描述】:

我在Xcode 8.3.3 上运行Swift。在这里我收到一个关于闭包的错误。

看来这部分是正确的[var intro = introToFriends("Jim", "Pam") intro] 但没有点击。

有什么问题?

【问题讨论】:

  • 将您的代码发布为能够复制的文本,而不是图像。
  • 使用 introToFriends(friendOne: "Jim",friendTwo: "Pam"), 参数名称
  • [swift] missing argument labels有60条搜索结果...

标签: ios swift xcode


【解决方案1】:

以后的 Swift 版本在调用函数时需要显式的参数标签。在您的情况下,它需要阅读:

var intro = introToFriends(friendOne: "Jim", friendTwo: "Pam")

或者,如果您在函数声明中为参数标签添加下划线,则可以允许省略参数标签的使用,例如:

func introToFriends(_ friendOne: String, _ friendTwoString) {
    ...
}

更多详情check the official Apple documentation on function argument labels

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2013-10-27
    • 2014-07-25
    相关资源
    最近更新 更多