Swift SpriteKit - View is equal to Nil


Hi,

I have been working on a game of which uses swipe controls but ran into a 'fatal error' which caused my application to crash on launch. Thankfully I have found the solution to this problem however I am not quite sure how to fix it. Here is the problem. As you can see in the 'didMoveToView' function, I have tried to add a gesture recogniser to the view but the view is for some reason an optional. Because of this, I have to place either an ! or a ? after the view. This may not seem a problem but when the view is followed by an ! it crashes because it attempts to unwrap an optional (the 'view') which is equal to nil. And whenever I follow view with a ? it just completely ignores the 'addGestureRecognizer' line of code. If anybody knows how to fix this and give the view a value, please reply as it would be much appreciated.


Thankyou,


Richard Eaves

It looks like you meant to post a code fragment, but it's not there.

Hi Quincey Morris, Your right I had posted an image with this question however it has not come through. I should have it up by Sunday. Thank you, Richard Eaves

Swift SpriteKit - View is equal to Nil
 
 
Q