How to cast AnyObject? to String in Swift 1.2

冷暖自知 提交于 2019-12-10 00:20:23

问题


Everything good until, I've downloaded the new version of Xcode 6.3 and Swift 1.2.

But when I compile my app again, a lots of error came out. I've dealt with most of them but there is a specific error that I couldn't figure it out the solutions

The error is "AnyObject? is not convertible to String?"

Before updating Xcode this was absolutely fine :

let firstName = self.currentUser["firstName"] as? String

回答1:


i've figured out the solution

let firstName = self.currentUser?["firstName"] as? String
if let firstname = firstName {
     // Continue
} else {
    // Handling the error.
}


来源:https://stackoverflow.com/questions/29543470/how-to-cast-anyobject-to-string-in-swift-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!