我必须在';Tswift 3.2
我正在从swift 2.2迁移到swift 3.2 发生了一些奇怪的行为,我得到了我不能得到的可选值 我的代码:我必须在';Tswift 3.2,swift,optional,Swift,Optional,我正在从swift 2.2迁移到swift 3.2 发生了一些奇怪的行为,我得到了我不能得到的可选值 我的代码: if let tmpStr = strFromFld?.replacingOccurrences(of: sess.decimalPoint, with: ".") { if convType == "buy" { print("Why optional here") print(tmpStr)
if let tmpStr = strFromFld?.replacingOccurrences(of: sess.decimalPoint, with: ".") {
if convType == "buy" {
print("Why optional here")
print(tmpStr) //this shows tmpStr is optional
print("???")
}
全功能,抱歉编码错误,请不要笑):
迁移到swift 4.1也无济于事(您的前提是错误的。
tmpStr
不是可选字符串。它是一个普通字符串,其文本包含单词“可选”。字符串本身表示“可选(1000)”
但这是一个正常的字符串。这是一个奇怪的行为。你尝试过清理构建文件夹吗?Malik,我想wis行为是Xcode 9.2的一个bug,下载Xcode 9.3。但是没有效果,清理(产品->清理)也没有效果。我使用的是Xcode 9.2,还没有遇到这个问题。您发布的代码中的代码块似乎缺少一个结束符}
,如果convatype==“buy”。如果让阻塞,此中是否还有其他代码?如果是,您可以共享它吗?另一方面,Xcode 9.3没有Swift 3.2。相反,它将默认为Swift 3.3(它有自己的一组问题)。一种可能的解释是,您传递的字符串包含“Optionl(…)”作为updateinfo(:)
的实际参数。请在调用updateinfo(:)
的位置显示您的代码。
func updateInfoForSum(_ strFromFld:String?) {
guard strFromFld != nil else {return}
if let tmpStr = strFromFld?.replacingOccurrences(of: sess.decimalPoint, with: ".") {
if convType == "buy" {
print("Why optional here")
print(tmpStr)
print("???")
infoSumConvert.text = "Сумма " +
WalletStuff.doubleToMoneyStr(
Double(
truncAfter2SymbolAfterDecimalDelimeter(
String(
NSString(string: tmpStr).doubleValue / selectedCurrency.saleRate!
).replacingOccurrences(of: ".", with: sess.decimalPoint)
).replacingOccurrences(of: sess.decimalPoint, with: ".")
)!
)
+ " \(selectedCurrency.name)"
} else {
infoSumConvert.text = "Сумма " +
WalletStuff.doubleToMoneyStr(
Double(
truncAfter2SymbolAfterDecimalDelimeter(
String(
NSString(string: tmpStr).doubleValue * selectedCurrency.buyRate!
).replacingOccurrences(of: ".", with: sess.decimalPoint)
).replacingOccurrences(of: sess.decimalPoint, with: ".")
)!
)
+ " UZS"
}
}
}