Search code examples
iosswiftsprite-kitsknode

SKNode! is not convertible to "SKNode"


I got this problem and can't resolve it, I don't really understand the documentation on unwrapping variables

var ladybug: SKNode = SKNode.childNodeWithName("ladybug")

Error: (String!) -> SKNode! is not convertible to "SKNode"

thanks


Solution

  • The method works fine:

    var sprite = SKNode()
    var ladybug: SKNode! = sprite.childNodeWithName("ladybug")
    

    But you need to call the method on an instance of SKNode, not SKNode itself.