I’m not sure I agree about readability, but each to his own.
One thing you should do (and this applies to all of your functions that take a block parameter and then runs it) is use rethrows i.e.
public func runThisBlock(block: () throws -> ()) rethrows
{
try block()
}
That way, people can pass a block that throws an exception if they want.
e.g.
let block = { print("Hi") } // Doesn’t throw
runThisBlock(block) // prints Hi
enum MyError: ErrorType
{
case Generic
}
let throwBlock = { throw MyError.Generic } // does throw
// The following prints Generic
do
{
try runThisBlock(throwBlock)
}
catch
{
print("\(error)")
> To view this discussion on the web visit
https://groups.google.com/d/msgid/swift-language/68f07e91-fb7d-4a64-847e-eefa4fb502a5%40googlegroups.com.