0

So I have a function that when called, needs to return a CGFloat value. However, Xcode responds with an error saying: "CGFloat is not convertible to ()". I have looked around the web, but none of the conversions seem to be working for me.

Here is my function

func update() {
    point2.y += 1.39
    return point2.y //<<<LINE OF ERROR<<<//
}
AstroCB
  • 12,337
  • 20
  • 57
  • 73
24GHz
  • 80
  • 1
  • 15

1 Answers1

1

Your function does not specify a return type.

In Swift, you denote this with arrow (->) notation.

Try

func update() -> CGFloat {
    point2.y += 1.39
    return point2.y
}

"CGFloat is not convertible to ()" means that your method returns something of type CGFloat, when a return type of Void (or ()) is expected.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
  • @24GHz I'm glad I could help. If this provided an answer to your question, consider [accepting it](http://stackoverflow.com/help/accepted-answer) so that we both gain [reputation](http://stackoverflow.com/help/whats-reputation). – AstroCB Dec 04 '14 at 04:50
  • Oh sure, yes. I have already accepted an answer recently, so I cant for another 4 minutes. But once that timer runs out I will most definitely accept it :) – 24GHz Dec 04 '14 at 04:51