Given the dictionary:
let dictionary = [ "one": 1, "two": 2, "three": 3]
I want to create a new version with one of the items removed based on its key. So I'm trying to use...
let dictionaryWithTwoRemoved = dictionary.filter { $0.0 != "two" }
... which achieves what I want HOWEVER the two dictionaries have differing types...
`dictionary` is a `[String: Int]`
`dictionaryWithTwoRemoved` is a `[(key: String, value: Int)]`
Which is consequently making my life difficult.
If I try to cast like so...
let dictionaryWithThreeRemoved = dictionary.filter { $0.0 != "three" } as! [String: Int]
...I get the following WARNING...
Cast from '[(key: String, value: Int)]' to unrelated type '[String : Int]' always fails
and the code also crashes with EXC_BAD_INSTRUCTION at runtime.
Help!
Dictionarydoes not have afilterfunction (yet). You are using thefilterfromSequencebutDictionaryis a sequence of key-value pairs. After callingfilter, it's not a dictionary any more, it's a list of key-value pairs.