Compile error in Chapter 12, page 330

let xInset = min(view.bounds.width/2 * camera.xScale, background.frame.width/2)
let yInset = min(view.bounds.height/2 * camera.yScale, background.frame.height/2)

Page 330, “view” type is SKView? so. following error is displayed.

Value of optional type ‘SKView?’ not unwrapped; did you mean to use ‘!’ or ‘?’?

So I fixed like followings

let xInset = min(view!.bounds.width/2 * camera.xScale, background.frame.width/2)
let yInset = min(view!.bounds.height/2 * camera.yScale, background.frame.height/2)

@hssong - I think you might have missed the second part of this line:

guard let camera = camera, let view = view else { return } 

at the top of setupCamera().

That’s where the view is unwrapped.

But your change works too :slight_smile: - it’s just that I try and avoid ! in code as it sometimes results in unexpected crashes.

2 Likes

Oh~ You are right!! Thanks.

That’s my mistake. I’m sorry. :slight_smile: