I'd like to add a default value to my async function. With completion handlers I can do it like this:
public protocol ServiceProtocol {
func getData(from startDate: Date, completion: @escaping (Result<MyModel, MyDefinedErrors>) -> Void)
}
// Protocol default values
extension ServiceProtocol {
public func getData(completion: @escaping (Result<MyModel, MyDefinedErrors>) -> Void) {
getData(
from: Date(timeIntervalSince1970: 0),
completion: completion
)
}
}
class MyClass: ServiceProtocol {
func getData(from startDate: Date, completion: @escaping (Result<MyModel, MyDefinedErrors>) -> Void) {
// some stuff here
}
}
But how can I do it using async? Here's the function I'm trying to convert:
func makeApiRequest<T: Decodable>(modelToDecode: T.Type, url: String, headerKey: String? = "", headerValue: String? = "", timeInterval: TimeInterval? = .infinity) async -> Result<T, NetworkError>