【问题标题】:Swift Code Error while creating option variable创建选项变量时出现Swift代码错误
【发布时间】:2015-12-25 19:04:46
【问题描述】:
var option = [NSObject : AnyObject]?.self
option = [CIDetectorSmile = true, CIDetectorEyeBlink = true, CIDetectorImageOrientation : 6]

错误:应为“,”分隔符

var features = faceDetector.featuresInImage(sourceImage, options: option)

错误:无法使用类型参数列表调用“featuresInImage”('CIImage,options: [NSObject : AnyObject]?Type?)

如何解决编译错误?

【问题讨论】:

    标签: ios iphone swift compiler-errors


    【解决方案1】:

    featuresInImage 具有以下签名:

    func featuresInImage(_ image: CIImage, options options: [String : AnyObject]?) -> [CIFeature]
    

    options 的类型为 [String : AnyObject]?。你的类型是[NSObject : AnyObject]?

    解决方法:使用

    var option : [String : AnyObject]? = [CIDetectorSmile : true, CIDetectorEyeBlink : true, CIDetectorImageOrientation : 6]
    

    由于您实际上始终提供始终提供选项,因此您甚至可以删除 ?

    补充说明

    Expected ',' separator 是由于您在字典值声明中使用了=: 造成的,请始终使用:

    【讨论】:

    • “一行的连续语句必须用';'分隔” “ 错误?这是什么意思?
    • @Vivek 以前是这样还是现在正在发生?如果它以前在那里,那是编译器对您对 := 的使用感到困惑
    猜你喜欢
    • 2014-05-25
    • 2015-06-25
    • 2011-11-06
    • 1970-01-01
    • 2021-04-15
    • 2016-06-01
    • 2020-02-03
    • 1970-01-01
    • 2015-06-19
    相关资源
    最近更新 更多