NEW: Learn to build the incredible iOS 15 Weather app today! >>

SOLVED: Filtering SKNodes ?

Forums > Swift

Is there a way to filter on a Class so that I can check for an SKLabelNode or an SKSpriteNode ?

e.g.

let nodes: [SKNode] = [spriteNode1, spriteNode2, labelNode1, labelNode2]

switch nodes.Type {
case .SKSpriteNode : print("this is a sprite node")
case .SKLabelNode : print("this is a label node")

Something like the above

   

Yes, you can try case is in the switch.

Something like: case is SKLabelNode etc.

But currently nodes.Types will give you back type of the array.

1      

Brilliant.

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.