TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.