Last active
January 5, 2016 15:31
-
-
Save robseward/d24e7bc15553ce93b50d to your computer and use it in GitHub Desktop.
Casting from type Any to AnyObject always fails when Any contains an optional
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 UIKit | |
var arr = [Any](); | |
var optionalString: String? = "foo"; | |
arr.append(optionalString); | |
print(arr[0]); // "Optional("foo")\n" | |
if let optionalValue = arr[0] as? AnyObject{ | |
print("success") // never executed... | |
} | |
else { | |
print("fail") // "fail" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment