GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

SOLVED: Project26 from 100 Days of Swift (UIKit) error - Cannot find 'addChild' in scope

Forums > 100 Days of Swift

I'm working on project 26 and got it all working but then I decided to move all the code that dealt with creating a level into its own struct.

Now, I get a compiler error on all the 'load' methods when calling addChild(node). I've searched around but wasn't able to find anything that explained this or how to fix it. I even tried chatGPT but it was no help.

What am I doing wrong?

Here is a gist of the struct

3      

@twostraws  Site AdminHWS+

The calls to addChild() should be inside your game scene, because that's where the method exists. Structs generally work best when they store simple, inert data, rather than trying to take action in your game.

3      

Thanks. I ended up removing the addChild() calls in the struct and then just created the nodes in my game scene by looping through an array created in the struct.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.