Skip to content

Instantly share code, notes, and snippets.

@nvh

nvh/optionals.swift

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.