Drakalex Drakalex - 2 months ago 10
Swift Question

Know if an array contains a type of element

I'm working with Swift 3 and Xcode.

I have a class :

class H: SKSpriteNode {...}

And an array :

var array = [H]()

I want to check with the
function if at given point, there is an element of type H. I tried :

if nodes(at: myPoint).contains(H)

But it doesn't work, and I understand that. Is there any way to be able to know if the arrays the
function returns contains an element from the class H ?

And an other question, how can I check in all the nodes returned by the function, if the array contains a node with a specific name ?


Try to use .filter({$0 is H}).count > 0