[英]Conditional cast from 'String' to 'String' always succeeds- Swift
I'm getting these errors: Error: Conditional cast from 'String' to 'String' always succeeds and Error: Cannot assign to value: 'anchorOffset' is a 'let'我收到这些错误:错误:从“字符串”到“字符串”的条件转换总是成功并且错误:无法分配给值:“anchorOffset”是一个“让”
let text = getTextPart()
if let text = text as? String {// Error: Conditional cast from 'String' to 'String' always succeeds
let lastOffset = text.lengthAsNSString()
var updatedAnchorOffset = lastOffset
var updatedFocusOffset = lastOffset
if var anchorOffset = anchorOffset {
updatedAnchorOffset = lastOffset
}
if var focusOffset = focusOffset {
updatedFocusOffset = lastOffset
} else {
anchorOffset = 0//Error: Cannot assign to value: 'anchorOffset' is a 'let' constant
focusOffset = 0//Error: Cannot assign to value: 'focusOffset' is a 'let' constant
}
}
This is my getTextPart():这是我的 getTextPart():
override func getTextPart() -> String {
guard let textNode = getLatest() as? TextNode else {
return text
}
return textNode.text
}
Remove this line删除此行
if let text = text as? String {// Error: Conditional cast from 'String'
Change the definition of anchorOffset and focusOffset to将 anchorOffset 和 focusOffset 的定义改为
var anchorOffset = something
var focusOffset = something
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.