for some reason, whenever i win the game, that is the player hits the target, the app crashes at line
playerPhysicsBody.node?.addChild(emitter!)
with an error
fatal error: unexpectedly found nil while unwrapping an Optional value
any help here please?
Asked
Active
Viewed 38 times
0

rmaddy
- 314,917
- 42
- 532
- 579

BTS DarkWings
- 1
- 1
-
you're assuming emitter is not nil, you should first check whether emitter exists. use "guard let" on the emitter instance – Luca Iaco Dec 07 '17 at 06:24
-
can u please show me how to do that.. i am not sure i have used guard let. thanks :) – BTS DarkWings Dec 07 '17 at 06:27
-
Read the linked duplicate. It explains it all. – rmaddy Dec 07 '17 at 06:40
1 Answers
0
Before Execute Check Whether Is Null Or Not.
if(playerPhysicsBody != nil){
playerPhysicsBody.node?.addChild(emitter!)
}

Jawahar Coder
- 1
- 2