gpt4 book ai didi

ios - 无法从字符串中删除可选的 Word?

转载 作者:行者123 更新时间:2023-11-30 12:55:17 25 4
gpt4 key购买 nike

无法删除可选字词

代码:

let questionidstr : String! = fetchResults.valueForKey("questionID").objectAtIndex(Counter) as? String

输出: 可选(16)

所需输出: 16

最佳答案

您正在使用 as 将其转换为可选字符串? String 并因此变得可选。请尝试以下操作:

if let questionidstr = fetchResults.valueForKey("questionID").objectAtIndex(Counter) as? String {
// Here, questionidstr will have a non optional value, but if it is nil the runtime will never get here.
}

您可以在没有条件绑定(bind)的情况下强制解开字符串,如下所示,但请注意这是不安全的,我不鼓励使用上述方法:

let questionidstr = fetchResults.valueForKey("questionID").objectAtIndex(Counter) as! String

关于ios - 无法从字符串中删除可选的 Word?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40482782/

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