SOLVED: "Unexpectedly found nil if implicitly unwrapping one optional value"...that I'd already gone the end of my means to verify must be valid.

You are watching: Unexpectedly found nil while unwrapping an optional value

Forums > Swift

So here"s the block of password in question:

if permit _ = UIImage(named: "(storyCharacter.spriteBaseName)-(status)") fileName = "(storyCharacter.spriteBaseName)-(status)" rather // shot just the default picture if one isn"t found for the condition if allow _ = UIImage(named: storyCharacter.spriteBaseName) fileName = storyCharacter.spriteBaseName rather // take it the defaults the end of the great if (storyCharacter.isGraphic == true) fileName = defaultGraphicImage else fileName = defaultCharacterImage // Skin the sprite as appropriate storyCharacter.currentSprite.texture = SKTexture(imageNamed: fileName) // due to the fact that it"s to be created and we"re technically re-skinning it...As you can see, I use UIImage to examine to ensure the the image to be dubbed for the texture exists without any type of question whatsoever, and also if ns fall back it check the fallback before going come a known, collection default image.

This code was working just fine ~ above my tools until I began running top top the simulator come test different screen sizes. Due to the fact that doing that, one specific image seems to have started throwing the off and producing the error in the title as soon as it fight the critical line. Ns re-loaded the on mine phone and it"s now doing the same error there wherein it wasn"t before. Haven"t tried putting the rebuilt version on my iPad appropriate now because I"m walk to be demoing this for someone this afternoon and also prefer to have actually one copy that"s still functioning right.

Question is, how can it be comes up as nil in this circumstance? Digging about in the debugger, ns did view the complying with in object 1, one level deeper than the offending role call:

0x1a497c230 : bl 0x1a497c598 ; closure #1 (Swift.UnsafeBufferPointer) -> () in Swift._assertionFailure(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never-> 0x1a497c234 : brk #0x1 // subject 1: deadly error: Unexpectedly found nil while implicitly unwrapping an Optional valueThanks for any insights!

OK, figured this one out on my own. Leaving the question up and sharing the price in situation someone else encounters a similar issue in the future.

Essentially, I have classes for controlling each personality in mine game, and those great are claimed to instantiate a sprite through the present representation of the character. The clip above comes from the regime that re-skins castle as required along the way.

I freshly finished adding unique prites for all of the characters, so ns was going with removing the currently instantiating the SKSpriteNodes with the placeholder sprite and also uncommenting the ones the pulled up the default sprite for the offered character. As it transforms out, in the class paper for the one character that kept tripping the error ns deleted the line with the placeholder, yet forgot to uncomment the line instantiating the sprite together intended.

See more: Devil Survivor 2 Record Breaker Dlc, Which Dlc Is Worth Getting

Thus, i was make the efforts to update the structure on one SKSpriteNode the didn"t exist, and that was what was being unwrapped in the error—not the string being fed through the heat I composed that triggered the error.