代码:
var messageList:[Message] = [] scrollToBottom(self.messageList, tableView:self.messageTableView) func scrollToBottom(dataList:[], tableView:UITableView){ } |
其中,此处的参数dataList,是想要兼容任意类型的数组Array作为参数输入都是支持的。
结果出错:
Expected element type
和:
Type annotation missing in pattern
搜:
swift Expected element type
swift Type annotation missing in pattern
Do you have to declare implicit type? | Treehouse Community
ios – Type annotation missing in pattern in swift 2.0 – Stack Overflow
ios – How do I declare an explicit type which conforms to a protocol? – Stack Overflow
Swift: Types of Data – a free Hacking with Swift tutorial
Do you have to declare implicit type? | Treehouse Community
swift [] array
想起来了:
用[AnyObject]估计就可以了?
func scrollToBottom(dataList:[AnyObject], tableView:UITableView){ |
真的可以了。
[总结]
想要实现,数组Array参数支持任意类型的数组,则可以写成:[AnyObject]就可以了。
转载请注明:在路上 » [已解决]swift代码出错:Expected element type和Type annotation missing in pattern