Skip to content

Instantly share code, notes, and snippets.

@oleksii-demedetskyi
Created April 7, 2016 14:34
Show Gist options
  • Save oleksii-demedetskyi/874104c31a2bb332ef2390ae5fc28bad to your computer and use it in GitHub Desktop.
Save oleksii-demedetskyi/874104c31a2bb332ef2390ae5fc28bad to your computer and use it in GitHub Desktop.
//: 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