Return CGValues Resulting in Xcode Error

69 Views Asked by At

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<<<//
}
1

There are 1 best solutions below

2
On BEST ANSWER

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.