Created
February 19, 2018 10:05
-
-
Save fitomad/2d51e3cfeb39a4667ae48b9cac631cb3 to your computer and use it in GitHub Desktop.
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
// An array with Int, Double and String types inside | |
let items: [Any] = [ 32, 32.0, "32" ] | |
for item in items | |
{ | |
switch type(of: item) | |
{ | |
case is Int.Type: | |
print("Type Int: \(item)") | |
case is Double.Type: | |
print("Type Double: \(item)") | |
case is String.Type: | |
print("Type String: \(item)") | |
default: | |
print("No sé que es") | |
} | |
} | |
/* | |
Results: | |
--- | |
Type Int: 32 | |
Type Double: 32.0 | |
Type String: 32 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A different way to chech a var type in Swift.
Include another way to use de switch control flow statement (case is)