简体   繁体   English

XCode 8上的Swift 3 Playground“对成员'joined()'的引用不正确

[英]Swift 3 Playground on XCode 8 "Ambiguous reference to member 'joined()' Error

I have the Dictionary: 我有字典:

let alphabet: [Character: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]

let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())

and that's when I get the error. 那就是我得到错误的时间。 How could I fix this and Why is it happening? 我该如何解决这个问题,为什么会发生? Any ideas? 有任何想法吗?

If you don't want to change your key type to String as already suggested, then map the Characters to Strings: 如果您不想像已经建议的那样将键类型更改为String,则将Characters map为Strings:

let alphabet: [Character: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet(charactersIn: alphabet.keys.map{String($0)}.joined())

The only thing you should change to make it work is the type of keys, from Character to String : 要使其正常工作,您唯一需要更改的就是键的类型,从CharacterString

let alphabet: [String: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM