I am using the following code to remove all of the dead projectile objects in my game, it works great however at random times it will crash and highlight the indicated line with this fatal error:
fatal error: unexpectedly found nil while unwrapping an Optional value(lldb)
Here is the code I am using, error is on line 4
projs.removeAtIndex(...)
if (Projectile.deadProjs.isEmpty == false && Projectile.projs.isEmpty==false) {
for i in 0...Projectile.deadProjs.count - 1 {
Projectile.projs.removeAtIndex(Projectile.projs.indexOf(Projectile.deadProjs[i])!);
}
Projectile.deadProjs.removeAll();
}