john doe john doe - 9 months ago 67
Swift Question

Conditional Binding for Optionals

I have the following code and it complains about the as! keyword. If I replace with as? it works fine.

enter image description here

Answer Source

You can't do force unwrapping in guard or if let. Use optionals. The end product which is name in your case is already an unwrapped value for you.

Replace as! with as?