any advice? says BAD_EXC_INSTRUCTIONS

switching Gamescene and it says Thread1: EXC_BAD_INSTRUCTIONS on if let cookie= level! line.. It says unexpectedly found nil while unwrapping an Optional value. But how do i fix that exactly? Any advice would be highly valued.

let (success, column, row) = convertPoint(location)

if success {

if let cookie = level!.cookieAtColumn(column, row: row) {

swipeFromColumn = column

swipeFromRow = row

showSelectionIndicatorForCookie(cookie)

if score >= level.targetScore {

}}

}

}

It says unexpectedly found nil while unwrapping an Optional value.

Then you have passed nil where you should not pass nil.


      if let cookie = level!.cookieAtColumn(column, row: row) {

If this is the right line which is causing the fatal error, check `level`.

With the code `level!`, you are telling Swift that "crash my app when `level` is nil".


Check how you have declared `level` and how you have assigned a value to it.

Okay i checked on it bro OOPer but after i came into a conundrem.. on my GameScene it says Property 'self.level' not initialized at super.init call. This is last thing i need to do for adding more levels resulting in the completion of my game so thank you.


override init(size: CGSize) {

super.init(size: size) <---- right here.

anchorPoint = CGPoint(x: 0.5, y: 0.5)


let background = SKSpriteNode(imageNamed: "Background")

addChild(background)

any advice? says BAD_EXC_INSTRUCTIONS
 
 
Q