I was trying to append my Point array with some data, although I got an error of type, shown below. Appreciate any help, thanks!
for i in slew {
var x = i[0]
var y = i[1]
pointsArray.append(Points.GetPoint(origin:Points.Point(x:x,y:y))) //Cannot invoke value of type 'Points.GetPoint.Type' with argument list '(origin: Points.Point)'
}
class Points: NSObject {
struct Point {
var x = Double(0.0)
var y = Double(0.0)
}
struct GetPoint {
var origin = Point()
var point: Point {
get {
let x = origin.x
let y = origin.y
return Point(x:x, y:y)
}
}
}
}
This is how the code should look like, not sure if you wanted to do a factory with the GetPoints
, but this is not a swift pattern.
for i in slew {
var x = i[0]
var y = i[1]
pointsArray.append(Points.Point(x:x,y:y))
}
class Points: NSObject {
struct Point {
var x = Double(0.0)
var y = Double(0.0)
}
}
To make it even more swifty you can use CGPoint
instead of your own point and make the for into a map.
pointsArray = slew.map { CGPoint(x: $0[0], y: $0[1]) }
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments