2

In Swift, how do I check if an arbitrary value, of static type Any, is an Array over any sort of type whatsoever?

As can be seen from running the snippet below, the obvious approach of checking if the value is Array<Any> does not work:

func isArray(v:Any) -> Bool
{
    if v is Array<Any> {
        return true
    }
    return false
 }

 let intArray:[Int] = [1,2,3]
 let anyArray:[Any] = [1,2,3]

 isArray(intArray) // => false
 isArray(anyArray) // => true
algal
  • 27,584
  • 13
  • 78
  • 80

0 Answers0