最新消息:20210917 已从crifan.com换到crifan.org

[已解决]swift代码出错:Expected element type和Type annotation missing in pattern

Swift crifan 3085浏览 0评论

代码:

    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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
96 queries in 0.194 seconds, using 23.32MB memory