I have this func:
func getOptionalConfigurations(_ configurations: ([String]?, Error?) -> Void) {
// DO SOMETHING
}
I need to wrap it in another like:
func retrieveConfigurations(_ completion:@escaping (([String]?) throws -> Void)) rethrows {
getOptionalConfigurations { (configurations: [String]?, error: Error?) in
do {
try completion(configurations)
} catch {
throw error
}
}
}
But I got this error:
Invalid conversion from throwing function of type '([String]?, Error?) throws -> ()' to non-throwing function type '([String]?, Error?) -> Void'
I agree with this error but I would still like to throw the error! I have no chance to change this func: getOptionalConfigurations.
EDIT: the first function is the translation of an ObjC function where at most I can modify the method signature adding something like NS_SWIFT
- (void)getOptionalConfigurations:(void (^)(NSArray <NSString *> * _Nullable configurations, NSError * _Nullable error))completion;
getOptionalConfigurationsto throw an error? - Ahmad Frethrowsin your case; Rethrowing functions must have at least one throwing function parameter (which isgetOptionalConfigurationsin your case). - Ahmad F