UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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


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


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.


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!

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.