How can I check in Swift if a value is an Array. The problem is that an array of type Int
can apparently not be casted to an array of type Any
. Suppose I have an array myArray
of type Int
and execute the following:
if let array = myArray as? [Any] { return true }
it doesn't return true (which surprises me actually). The same thing appears with dictionaries. I want a dictionary of type String, Any
(meaning that Any
can be any type). How can I check if it is?
Thanks in advance.
Any
, so what your statement is effectively saying is "If this array is an array, return true"... the compiler is already well aware that it is an array. – StuartmyArray
would be an object that is not of typeArray
.NSJSONSerialization
produces object types, so a scalar integer would be aNSNumber
- this allows you to useAnyObject
regardless of the value in the JSON array/dictionary. – Stuart