Question : Difference between Any vs. AnyObject
Answer : Any can represent an instance of any type at all, including function types and optional types.
AnyObject can represent an instance of any class type.
I tried to store a function type in a Any and a AnyObject variables
func add(a: Int, b: Int) -> Int {
return a + b
}
let funcType = add
let test1: Any = funcType
let test2: AnyObject = funcType//Value of type '(Int, Int) -> Int' does not conform to specified type 'AnyObject' Insert ' as AnyObject'
When I use the fix option
let test2: AnyObject = funcType as AnyObject
It works without any error. How am I able to store a function type in a AnyObject?