【问题标题】:CIDetectorError: '(String, CIContext?, [String : Any]?) -> CIDetector' is not convertible to '(String, CIContext?, [String : Any]?) -> CIDetector?'CIDetectorError: '(String, CIContext?, [String: Any]?) -> CIDetector' 不能转换为 '(String, CIContext?, [String: Any]?) -> CIDetector?'
【发布时间】:2017-04-14 01:44:07
【问题描述】:

转换为Swift 3.0 后,由于某种原因我收到此错误

'(String, CIContext?, [String: Any]?) -> CIDetector' 不能转换为'(String, CIContext?, [String: Any]?) -> CIDetector?'

//When initiating 
let detector: CIDetector? = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])

我只在尝试存档时收到错误消息。当我运行时,一切正常。

【问题讨论】:

标签: swift3 xcode8.1 cidetector


【解决方案1】:

这是显式类型注释毫无意义的一个很好的例子。

去掉类型注解,让编译器推断类型

let detector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])

错误消息指出返回类型是非可选的。

【讨论】:

  • 谢谢@vadian。仍然得到这个错误。它确实编译。我只在Archive 时收到此错误。类型是String,仍然不知道为什么会弹出这个错误。
【解决方案2】:

没有声誉可以评论,所以想补充一下,这在一个月后的 XCode 8.1 中仍然是一个问题。仅在存档上。我在推断类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    相关资源
    最近更新 更多