Last active
May 30, 2018 11:56
-
-
Save dineshba/0b6e6d8b8416ae74ccf65e3d72e42fc1 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
var anyValue: Any // If we don't know the type at compile time, | |
// we can use `Any`. It is mostly used for data | |
// coming from network which can be type casted as below. | |
anyValue = "string value" // assinging string value | |
anyValue is String // true | |
// type checking using `is` operator | |
if let stringValue = anyValue as? String { // if anyValue is castable to String, it will | |
print(stringValue.uppercased()) // store in stringValue and enter into `if-let` | |
} | |
anyValue = Programmer() | |
if let programmer = anyValue as? Programmer { | |
print(programmer.laptop) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment