Swift 3 Playground on XCode 8“对成员的引用不明确 'joined()' 错误
Swift 3 Playground on XCode 8 "Ambiguous reference to member 'joined()' Error
我有词典:
let alphabet: [Character: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())
那是我收到错误的时候。我该如何解决这个问题,为什么会这样?
有什么想法吗?
你唯一应该改变的是键的类型,从 Character
到 String
:
let alphabet: [String: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())
如果您不想按照已经建议的那样将密钥类型更改为字符串,则 map
将字符更改为字符串:
let alphabet: [Character: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet(charactersIn: alphabet.keys.map{String([=10=])}.joined())
我有词典:
let alphabet: [Character: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())
那是我收到错误的时候。我该如何解决这个问题,为什么会这样? 有什么想法吗?
你唯一应该改变的是键的类型,从 Character
到 String
:
let alphabet: [String: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())
如果您不想按照已经建议的那样将密钥类型更改为字符串,则 map
将字符更改为字符串:
let alphabet: [Character: Int] = ["a": 0, "b": 1, "c": 2, "d": 3]
let validSet = CharacterSet(charactersIn: alphabet.keys.map{String([=10=])}.joined())