Why should grails actions be declared as methods instead of closures and what difference does it make?

The answer is here From above link Leveraging methods instead of Closure properties has some advantages: Memory efficient Allow use of stateless controllers (singleton scope) You can override actions from subclasses and call the overridden superclass method with super.actionName() Methods can be intercepted with standard proxying mechanisms, something that is complicated to do with Closures … Read more

Blocks on Swift (animateWithDuration:animations:completion:)

The completion parameter in animateWithDuration takes a block which takes one boolean parameter. In Swift, like in Obj-C blocks, you must specify the parameters that a closure takes: UIView.animateWithDuration(0.2, animations: { self.blurBg.alpha = 1 }, completion: { (value: Bool) in self.blurBg.hidden = true }) The important part here is the (value: Bool) in. That tells … Read more

How to use Swift @autoclosure

Consider a function that takes one argument, a simple closure that takes no argument: func f(pred: () -> Bool) { if pred() { print(“It’s true”) } } To call this function, we have to pass in a closure f(pred: {2 > 1}) // “It’s true” If we omit the braces, we are passing in an … Read more