码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-15 23:00:50      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:swift error

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

标签:swift error

原文地址:http://blog.csdn.net/soindy/article/details/46896853

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!