In Swift, how can I check if an element exists in an array? Xcode does not have any suggestions for contain, include, or has, and a qu
Swift 4.2 +
You can easily verify your instance is an array or not by the following function.
func verifyIsObjectOfAnArray(_ object: T) -> Bool {
if let _ = object as? [T] {
return true
}
return false
}
Even you can access it as follows. You will receive nil if the object wouldn't be an array.
func verifyIsObjectOfAnArray(_ object: T) -> [T]? {
if let array = object as? [T] {
return array
}
return nil
}