iOS Closures in Swift Error Handling and Memory Management Rethrowing An Error

Roland Schützenhofer
Roland Schützenhofer
4,311 Points

Is this really safe?

I'm not sure if it is really safe to use the "rethrows" method. In the code below the compiler doesn't show an error, but in approximately 50% of executions this will produce a runtime error.

var randomNumber = customRandomNumber(from: 0, to: 2) var number: Int if randomNumber > 1 { number = 0 } else { number = 1 }

10.apply(number) { $0/$1 }