Unwrapping optionals XCODE 11

Struggling with a fairly simple bit of code
This is part of a basic Game SpriteKit setup where I am getting a ball to bounce around a physical boundary

This is an adaption of a RayWenderlich tutorial to build a Breakout game.

Uwrapping optionals hurts my head. I’m assuming the issue is unwrapping SKSpriteNode rather than my own variable??
here’s my code

Either one, as ball is nil. You can put a break point above the call and step through, I expect it is passing a piece of code somewhere, likely a typo of a name.


Yes I keep thinking it must be the image or sprite name typo

Tried breakpoint but doesn’t tell me very much

I have the tutorial version working fine which was started from the downloaded starter file. But can’t find any difference between my code and the starter setup. Maybe some preference settings which affects how optionals are handled?

I would set a break point and just before the crash point where ball is nil, I would check to see if ballCategoryName is nil or more importantly, childNode.

From the Apple Docs: If a node object with that name is found, the method returns the node object. Otherwise, it returns nil

Step into rather than step over can help in these situations.


is your sprite added properly with the correct name? “redBall”?

it seems that it fail to find the childnode with the name redBall