gpt4 book ai didi

快速编译错误: Downcast from 'String?!' to 'String' only unwraps optionals; did you mean to use '!!' ?

转载 作者:可可西里 更新时间:2023-11-01 00:36:33 25 4
gpt4 key购买 nike

升级到 cocoapods 1.0 后,我得到以下代码行的编译错误:

var strName = String()
var strEmail = String()
var strFacebookID = String()
var strPassword = String()
var objHelper = Helper()

....

let strFirstName = result["first_name"] as! String
let strLastName = result["last_name"] as! String
self.strName = strFirstName + "_" + strLastName
self.strEmail = result["email"] as! String
self.strFacebookID = result["id"] as! String

Downcast from 'String?!' to 'String' only unwraps optionals; did you mean to use '!!'?

这里是错误的详细截图: http://imgur.com/Efe1nQf

更新:更多代码在这里:https://gist.github.com/anonymous/9c91c2eb1ccf269e78a118970468d1e8

最佳答案

错误消息说 result 本身是可选的,因此您必须分别解包 result 和值。

let strFirstName = result!["first_name"] as! String

或更好地使用可选绑定(bind)以获得更高的安全性和更少的类型转换

if let userData = result as? [String:String] {
let strFirstName = userData["first_name"]!
let strLastName = userData["last_name"]!
}

关于快速编译错误: Downcast from 'String?!' to 'String' only unwraps optionals; did you mean to use '!!' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37350503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com