Value of type 'CGPoint' has no member 'makeWithDictionaryRepresentation' in swift 3

拈花ヽ惹草 提交于 2019-12-25 08:58:45

问题


I am working with Swift 3. In my code I am using Siri integration in Wallet App.I am getting an error in that App. I searched in google for it but I didn't find the solution for it.

Here is my code:

 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
    }

Here is the error I am getting:

Value of type 'CGPoint' has no member 'makeWithDictionaryRepresentation'

Can any anyone Please help me resolve it. Thanks in Advance.


回答1:


In Swift 3 you need to use init CGPoint(dictionaryRepresentation:).

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

It will return optional CGPoint instance so batter to use with if let or guard

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

Check Apple Documentation on CGPoint for more details.



来源:https://stackoverflow.com/questions/40925984/value-of-type-cgpoint-has-no-member-makewithdictionaryrepresentation-in-swif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!