Swift 2 array of tuples not working as in swift 1

社会主义新天地 提交于 2019-12-17 21:23:21

问题


Array:

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

the append line is giving me following error since I upgraded to swift 2:

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

in swift 1 it was working fine. Any idea whats wrong?


回答1:


You're appending the parameters list, not the tuple itself: you're missing a pair of ().

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



回答2:


Oh, OK, you need more parentheses.

At the moment you're providing a list of 4 parameters.

You need one tuple parameter like this...

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


来源:https://stackoverflow.com/questions/32654654/swift-2-array-of-tuples-not-working-as-in-swift-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!