【问题标题】:'...' is not a postfix unary operator - Swift 3'...' 不是后缀一元运算符 - Swift 3
【发布时间】:2018-01-18 15:33:16
【问题描述】:

我只想删除字符串的一部分。

if let dotRange = detailArticleContent?.range(of: "<iframe") {

    detailArticleContent.removeSubrange( dotRange.lowerBound... < detailArticleContent.endIndex )
    //In this line i got err : '...' is not a postfix unary operator 

   }

【问题讨论】:

  • 你为什么还要放这个运算符呢?与
  • 我想要这样的字符串的一半 detailArticleContent = detailArticleContent.componentsSeparatedByString("
  • 因为是可选字符串,所以需要检查分离后是否有内容
  • 我在调试器中跟踪值,但我会仔细检查确定
  • 不在调试器中跟踪,签入代码让编译器知道一切正常,分离的组件将可用

标签: ios xcode cocoa-touch swift3 operators


【解决方案1】:

使用...(近距离)或..&lt;(半近距离,在最后),没有什么比得上... &lt;

【讨论】:

    【解决方案2】:

    在我的例子中,我在 0.. 和 dictionary.count 之间给出了空格

    正确的是:

    0..<dictionary.count
    
    //Wrong 
    let dictionary = dic["predictions"] as! [String:Any]
        print(dictionary)
        for index in 0..< dictionary.count {
            print(<#T##items: Any...##Any#>)
        }
    
    //Correct 
    let dictionary = dic["predictions"] as! [String:Any]
        print(dictionary)
        for index in 0..<dictionary.count {
            print(<#T##items: Any...##Any#>)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多