Created
April 7, 2016 14:34
-
-
Save oleksii-demedetskyi/874104c31a2bb332ef2390ae5fc28bad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//: Playground - noun: a place where people can play | |
import Foundation | |
func cast<T>(any: Any) -> T { | |
print(T.self) // Optional<String> | |
print(any) // nil | |
let value = any as! T | |
//Could not cast value of type 'Swift.Optional<Swift.String>' (0x11ad4b028) to 'Swift.String' (0x1118024c8). | |
print(value) | |
return value | |
} | |
let value = .None as String? | |
let any = value as Any | |
let castedBacl: String? = cast(any) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment