0
public static func easeOutQuint(_ t: Float, _ b: Float, _ c: Float, _ d: Float = 1.0) -> Float {
    return {
        return c * ($0 * $0 * $0 * $0 * $0 + 1.0) + b
    }(t / d - 1.0)
}

I'm not familiar with closure, so I can not fix it by myself, can someone help me?

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
Henson Fang
  • 1,177
  • 7
  • 30
  • 1
    I ran your code in playground , it works fine for me, can you please elaborate more about the usage of your function – 3stud1ant3 Nov 01 '17 at 03:14
  • i start a new project and copy it to the new project,it works fine,but i just fails in my own project. – Henson Fang Nov 01 '17 at 03:23
  • 2
    `$0 * $0 * $0 * $0 * $0`? Why not just `pow($0, 5)`? – Alexander Nov 01 '17 at 03:23
  • @HensonFang If you don't understand your own code how would you expect us to do it. I can explain to you what `$0` means in your closure. `$0` is the result of your equation `(t/d - 1.0)`. Note that the return keyword there is redundant. As already mentioned by Alexander you can replace `$0 * $0 * $0 * $0 * $0`by `pow($0, 5)`. So you could simplify your code as follow: `return { c * (pow($0, 5) + 1.0) + b } (t / d - 1.0)` – Leo Dabus Nov 01 '17 at 04:11

1 Answers1

0

Closures are a great tool but, in this particular example, you would be better off without them IMO...

For instance, you could rewrite your function simply as:

public static func easeOutQuint(_ t: Float, _ b: Float, _ c: Float, _ d: Float = 1.0) -> Float {
    let x = (t / d - 1.0)
    return c * (pow(x, 5) + 1) + b
}

And, by the way, this should compile just fine in any Swift compiler you come across ;)

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85