I need to create a self-executing block in Swift, similar to what we had in Objective C:
{
/* statements */
}
However the same construct in Swift yields "braced block of statements in unused block".
I need to create a self-executing block in Swift, similar to what we had in Objective C:
{
/* statements */
}
However the same construct in Swift yields "braced block of statements in unused block".
At the moment, I use:
if true {
/* ... */
}
Any better solution is welcome.
UPDATE 2: Swift 2 now has a new control structure do
:
do {
/* ... */
}
UPDATE: Another answer is found here:
func locally(work: () -> ()) {
work()
}
...
locally {
/* ... */
}
This looks nice, except that due to Swift's rules, you have to use self.property
instead of just property
inside the block.