Skip to content

Instantly share code, notes, and snippets.

@robseward
Last active January 5, 2016 15:31
Show Gist options
  • Save robseward/d24e7bc15553ce93b50d to your computer and use it in GitHub Desktop.
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
//: 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