Friday, May 20, 2016

Testing IBOutlets and IBActions With Curried Functions in Swift

Ben Chatelain:

Currying helps to simplify these outlet and action test functions so that the view controller doesn’t have to be passed in every function call. Just like the sumA function holds onto the value of the first parameter, these test functions hold onto a reference to the view controller being tested. There’s also the benefit of being able to give the returned function a very readable name.

[…]

So, what is that hasButtonOutlet magic? It’s a partially-applied function saved in a local variable.

[…]

Shortly after @allonsykraken posted Hipster Swift, I learned that the super-clean syntactic sugar version of curried functions is going away in Swift 3 and it made me sad.

Comments RSS · Twitter

Leave a Comment