How to create immediately callable functions (blocks) in Swift
1 answer
I am currently using:
if true {
/* ... */
}
Any better solution is appreciated.
UPDATE 2 : Swift 2 now has a new control structure do
:
do {
/* ... */
}
UPDATE . Another answer found here :
func locally(work: () -> ()) {
work()
}
...
locally {
/* ... */
}
This looks good, except that due to Swift rules, you need to use self.property
instead property
inside a block.
+2
source to share