Skip to content

Instantly share code, notes, and snippets.

@nvh
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvh/cd6a1839c022ce962544 to your computer and use it in GitHub Desktop.
Save nvh/cd6a1839c022ce962544 to your computer and use it in GitHub Desktop.
Test for optionals
extension Dictionary {
func test() {
for (key,value) in self {
//Works
if value is Int {
println("int")
}
//Throws compiler error: cannot downcast from 'Value' to a more optional type 'Int?'
if value is Int? {
println("optional int")
}
}
}
}
var dict: [String: Int] = ["four":4,"five":5]
var dictWithOptionals: [String: Int?] = ["four":4,"five":nil]
dict.test()
dictWithOptionals.test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment