Compile error in Ch 9 Intermediate Physics

I’m totally missing something here. I see someone else has had this, figured it out, and didn’t say what the problem was.

Here’s the issue in Xcode:

45%20PM

I’m not seeing where I’ve gone wrong and would appreciate a pointer.

Thank you

You have not gone wrong, it is just a warning. There are two ways to deal with it. You can see these options if you click the yellow triangle just before each warning message.

  1. Use as? instead of as!:
    bedNode = childNode(withName: "bed") as? BedNode

This could return a nil, which would then cause the line bedNode.setScale(1.5) to fail, since bedNode is declared with a forced unwrap and is not supposed to be nil.

  1. Put parentheses around the entire expression:
    catNode = (childNode(withName: "//cat_body") as! CatNode)

This just suppresses the warning message, and will still fail immediately if the result
would be nil. This is the one I used.

Thank you! Now I understand

This topic was automatically closed after 166 days. New replies are no longer allowed.