Cannot find an initializer for type '[(String)]' that accepts an argument list of type '(LazyForward

Cannot find an initializer for type '[(String)]' that accepts an argument list of type '(LazyForward,第1张

概述Swift编译错误: Cannot find an initializer for type '[(String)]' that accepts an argument list of type '(LazyForwardCollection<MapCollectionView<Dictionary<Int, String>, Int>>)' 错误代码:         var dict = [1

Swift编译错误:Cannot find an initializer for type '[(String)]' that accepts an argument List of type '(LazyForwardCollection<MapCollectionVIEw<Dictionary<Int,String>,Int>>)'

错误代码:

var dict = [1: "m",2: "i",3: "i",4: "s"]


let dictKeysArray = [String](dict.keys)


根据字典字面量推断,该字典的类型是<Int: String>.即key为Int类型.错误的原因就是你用Int类型的初始化了key,现在又用String类型的取.所以会报该编译错误.


正确写法:

let dictKeysArray = dict.keys

或者将String改成Int. 总结

以上是内存溢出为你收集整理的Cannot find an initializer for type '[(String)]' that accepts an argument list of type '(LazyForward全部内容,希望文章能够帮你解决Cannot find an initializer for type '[(String)]' that accepts an argument list of type '(LazyForward所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1086398.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存