0

I'm fairly new to swift and I'm creating a grapple hook mechanic and I'm trying to draw a line between the hook and the player when the screen is tapped, but I keep coming up with Missing Argument for parameters in call which I don't know what to make of it. I've researched and tried multiple things, I know there is multiple question about this error, but I can't relate it to my problem. I think the fact that I am new has a lot to do with it.

let ropePath = CGMutablePath()
CGPathMoveToPoint(ropePath, player.position.x, player.position.y)
CGPathAddLineToPoint(ropePath, ropeTarget.position.x, ropeTarget.position.y)
rope.path = ropePath
rope.strokeColor = UIColor.red
rope.lineWidth = 8

The errors are on both the CGPaths, I can tell you everything I try creates a different error that is:

Cannot convert CGFloat to expected argument type UnsafePointer CGAffineTransform

So I guess my question is how do I convert the CGFloat to the correct argument?

Also if this is a really simple fix could you possibly explain or link some documentation that will help me better understand? Thank you!

Amit
  • 4,837
  • 5
  • 31
  • 46
Darin Wilson
  • 169
  • 1
  • 2
  • 9
  • You are missing the second (`m`) parameter ([see the function signature here](https://developer.apple.com/documentation/coregraphics/1411138-cgpathaddlinetopoint)) where you optionally specify a transformation matrix. You could pass `nil` if no transformation is needed. So something like this (for both calls) would work: `CGPathMoveToPoint(ropePath, nil, player.position.x, player.position.y)` – Alladinian Oct 13 '17 at 15:10
  • @Alladinian: As of Swift 3 it is `ropePath.move(to: ...)` and `ropePath.addLine(to: ...)` – Compare https://github.com/apple/swift-evolution/blob/master/proposals/0044-import-as-member.md. – Martin R Oct 13 '17 at 15:16
  • I've tried nil and the error that pops up is that nil is not compatible with expected argument. :-/ – Darin Wilson Oct 13 '17 at 15:23
  • @MartinR True. I just assumed that OP was working on an old project since the question was not mentioning a specific Swift version. – Alladinian Oct 13 '17 at 15:32
  • @DarinWilson If you're on Swift3+ then you could migrate to the "[modernized](https://developer.apple.com/documentation/coregraphics/cgmutablepath)" apis as mentioned by Martin – Alladinian Oct 13 '17 at 15:35

0 Answers0