在这里设置fullLength
的正确方法是什么?
var index = foo.index(foo.startIndex, offsetBy: SOME_NUM)
let length = Int(foo.substring(to: index))
if let fullLength = length? + SOME_NUM {
return
}
这里的问题是 length?
是可选的。我有这个工作:
fullLength = 长度! + SOME_NUM
,但我不想冒险在 length
为 nil 的情况下使用 !
。
最佳答案
你可以改写为
if let length = length {
let fullLength = length + SOME_NUM
}
关于swift - 在 Swift 3 中解包可选整数的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41453807/