I'm working with something trivialized to this:
func isAnyObject<T>(someObject: T) {
if let object = someObject as? AnyObject {
// do something
} else {
// do something else
}
}
Which gives me the compiler warnings:
- Conditional cast from 'T' to 'AnyObject' always succeeds
- Non-optional expression of type 'AnyObject' used in a check for optionals
I understand why the cast always succeeds, but I don't know what to do to fix it. I tried changing line 2 to
if let object = foo as AnyObject?
but when I pass a struct through the function, it still gets into the 'if' block. What am I missing here?