Last active
August 29, 2015 14:19
-
-
Save nvh/cd6a1839c022ce962544 to your computer and use it in GitHub Desktop.
Test for optionals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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