【问题标题】:Value of type 'CGPoint' has no member 'makeWithDictionaryRepresentation' in swift 3'CGPoint' 类型的值在 swift 3 中没有成员'makeWithDictionaryRepresentation'
【发布时间】:2016-12-02 06:18:28
【问题描述】:

我正在使用 Swift 3。在我的代码中,我在 Wallet App 中使用 Siri 集成。我在该 App 中遇到错误。我在谷歌上搜索了它,但我没有找到它的解决方案。

这是我的代码:

 func createPath(_ points: NSArray) -> UIBezierPath {
        let path = UIBezierPath()
        var point = CGPoint()

        //CGPointMakeWithDictionaryRepresentation((points[0] as! CFDictionary), &point)
        point.makeWithDictionaryRepresentation((points[0] as! CFDictionary)) // In this line I am getting an error
        path.move(to: point)

        var index = 1
        while index < points.count {

            //CGPointMakeWithDictionaryRepresentation((points[index] as! CFDictionary), &point)
            point.makeWithDictionaryRepresentation((points[index] as! CFDictionary))
            path.addLine(to: point)

            index = index + 1
        }
        path.close()

        return path
    }

这是我得到的错误:

“CGPoint”类型的值没有成员“makeWithDictionaryRepresentation”

任何人都可以帮我解决它。 提前致谢。

【问题讨论】:

  • 错误清楚地表明CGPoint 没有像makeWithDictionaryRepresentation 这样的成员。那么如何设置或调用它呢?
  • 参考Apple doc

标签: ios swift swift3 cgpoint


【解决方案1】:

在 Swift 3 中,您需要使用 init CGPoint(dictionaryRepresentation:)

let point = CGPoint(dictionaryRepresentation:points[0] as! CFDictionary)

它将返回可选的CGPoint 实例,以便与if letguard 一起使用

if let point = CGPoint(dictionaryRepresentation:points[0] as! CFDictionary) {
     print(point)
}

查看CGPoint 上的 Apple 文档了解更多详情。

【讨论】:

  • @hrithib 欢迎伙伴 :) 如果您选择使用 if let 而不是使用 ! 强制包装,它可能会导致您崩溃,如果它不转换它可能会导致您崩溃`CFDictionary`.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多