简体   繁体   English

从“字符串”到“字符串”的条件转换总是成功 - Swift

[英]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.

相关问题 从 String 到 NSString 的条件转换总是成功 - Conditional cast from String to NSString always succeeds 从'String'到'String'的条件向下转换总是成功 - Swift Error - Conditional downcast from 'String' to 'String' always succeeds - Swift Error 来自 UIViewController 的条件转换总是成功 | 斯威夫特/Xcode - Conditional cast from UIViewController always succeeds | Swift/Xcode 从字符串到字符串的有条件强制转换总是迅速完成 - Conditional cast from string to string always succeds in swift 3 Swift:确定从字符串转换为整数是否成功 - Swift: Determining if cast to integer from string succeeds 从“UIButton”到“UIButton”的条件转换总是成功 - Conditional cast from 'UIButton' to 'UIButton' always succeeds 从 'AFError' 到 'AFError' 的条件转换总是成功 - Conditional cast from 'AFError' to 'AFError' always succeeds 黄色警告:从“AVCaptureVideoPreviewLayer”到“AVCaptureVideoPreviewLayer”的条件转换总是成功 - Yellow warning: Conditional cast from 'AVCaptureVideoPreviewLayer' to 'AVCaptureVideoPreviewLayer' always succeeds 如何删除警告“从'Any'到'AnyObject'的有条件强制转换始终成功” - How to remove warning “Conditional cast from 'Any' to 'AnyObject' always succeeds” 黄色警告:从UITextDocumentProxy到UIKeyInput的条件强制转换始终成功 - yellow Warnings : Conditional cast from UITextDocumentProxy to UIKeyInput always succeeds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM