I have the following code and it complains about the as! keyword. If I replace with as? it works fine.
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?