【问题标题】:No '|' candidates produce the expected contextual result type 'NSTextStorageEditActions'没有'|'候选人产生预期的上下文结果类型'NSTextStorageEditActions'
【发布时间】:2016-04-11 22:10:27
【问题描述】:

我通过Text Kit Tutorialraywenderlich.com 和线路

edited(.EditedCharacters | .EditedAttributes, range: range, changeInLength: (str as NSString).length - range.length)

产生以下错误:

No '|' candidates produce the expected contextual result type 'NSTextStorageEditActions'

当我将第一个参数更改为:

edited(.EditedCharacters, range: range, changeInLength: (str as NSString).length - range.length)

我也尝试过使用“OR”和“||”没有任何成功。

Swift 2.2 和 iOS 9.2

【问题讨论】:

  • NSTextStorageEditActions 现在(似乎本教程是 Swift 2.0 之前的)符合 OptionSetType 协议,您可以使用类似数组的语法 [.OptionA, .OptionB] 包含多个选项。例如,在您的示例中,edited([.EditedCharacters, .EditedAttributes], ... 。详情请see e.g. this Q&A.
  • 啊!那行得通 - 谢谢!

标签: ios swift


【解决方案1】:

@dfri 是正确的。为了说明使用管道“|”的另一个示例,是在为 UIImageView 执行 autoResizingMask 时,如下所示:

imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight, ...]

当然,您可以将 ... 替换为其他 UIViewAutoresizing 选项。

祝你好运!

【讨论】:

    【解决方案2】:

    将它们全部放在一个数组中,如下所示:

    而不是管道

    let timeDateComponents = calendar.components(NSCalendarUnit.Hour| NSCalendarUnit.Minute| NSCalendarUnit.Second, fromDate: NSDate())
    

    试试这个

    let timeDateComponents = calendar.components([NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: NSDate())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多