How to check if the object returned is Array in Swift

Ankit Srivastava

I have a declaration..

var cabResults = Dictionary<CabType, [CabResult]>()

Now I want to check if the object is present in the dictionary for a particular key.. which can be don by

if self.cabResults[currentCabType] != nil

Now I also want to check if the object returned by self.cabResults[currentCabType] is of type [CabResult]

How can I get this..?

Eric Aya

I would use if let ... as? ...:

if let cabs = self.cabResults[currentCabType] as? [CabResult] {
    // yep
} else {
    // nope
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to check the duplicate object in the array

Rest-assured. How to check if not empty array is returned?

How to check if an object is an array?

How to check object is nil or not in swift?

How to check empty object array?

iOS Swift: how to check if Object exists in an Array so I don't add it to it, or re-create a GMSMarker with it?

How do I check if an object is a collection? (Swift)

How to check if Object is NOT in array in mongoDb?

How to check if an object is dictionary or not in swift 3?

Swift 4 JSON Codable - value returned is sometimes an object, others an array

How to check multiple objects in another array in Swift?

In Powershell, How do I get the Values out of an array returned by an object?

How to check for a key in json object returned by jquery post?

How to fix map typerror when a promise object is returned before the array?

How to check last array object

Swift: How to check a core data NSSet for an object

How to return an array of object properties from a returned object of Laravel Eloquent

How to check array object and array?

How to check in Swift if an object it's invalid?

How to check equality of object properties in an array of objects. Swift

Swift: array check for object at index

Check if swift array does not contain object

How can I check if an object is returned from a filter call?

How to check if variable is an object or an array?

How to override a key of an object in an array of objects returned from mongodb?

How to check the length of a returned array from a pipe in an angular test?

How to check if array of object is empty?

How to check whether an array of object is present in another array of object in Javascript

how to check a condition in object array