Am I missing something here? I cannot see a reason that this would not compile...
protocol StringValidationRule {
func validate(string: String) throws -> Bool
var errorType: StringValidationError { get }
}
extension Array where T: StringValidationRule {
func validateEach(string: String, completion: (valid: Bool, error: StringValidationError?) -> ()) {
for rule in self {
do {
try rule.validate(string)
completion(valid: true, error: nil)
} catch let error as StringValidationError {
completion(valid: false, error: error)
} catch {
fatalError("Unexpected error type")
}
}
}
}
var validationRules = ...
validationRules.validateEach("") { (valid, error) -> () in
}
Line 23 throws the following error:
error: cannot invoke 'validateEach' with an argument list of type '(String, (_, _) -> ())'
validationRules.validateEach("") { (valid, error) -> () in