【问题标题】:Swift 2 array of tuples not working as in swift 1Swift 2 元组数组不像 Swift 1 那样工作
【发布时间】:2015-09-18 14:36:20
【问题描述】:

数组:

var rows: [(title: String, body: String, icon: String, iconColor: UIColor)] = []
rows.append(title: "Foo", body:"Bar", icon: "Bas", iconColor: UIColor(netHex: 0x4285f4))

自从我升级到 swift 2 后,附加行给了我以下错误:

Cannot invoke append with argument list of type (title: String, body: String, icon: String, iconColor: UIColor)

在 swift 1 中它工作正常。知道有什么问题吗?

【问题讨论】:

  • 参数列表类型是什么...?
  • @Fogmeister 更新 Q

标签: swift swift2


【解决方案1】:

您添加的是参数列表,而不是元组本身:您缺少一对()

rows.append((title: "Foo", body:"Bar", icon: "Bas", iconColor: UIColor(netHex: 0x4285f4)))

【讨论】:

    【解决方案2】:

    哦,好的,你需要更多的括号。

    目前您提供了一个包含 4 个参数的列表。

    你需要一个这样的元组参数...

    rows.append((title: "Foo", body:"Bar", icon: "Bas", iconColor: UIColor(netHex: 0x4285f4)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      相关资源
      最近更新 更多