Pregunta de entrevista de Yandex

You have a struct "Worker" with method that fetches one worker by id. Write method that will fetch multiple workers by array of ids.

Respuesta de la entrevista

Anónimo

17 jul 2019

struct Worker { func fetch(objectWithId id: String, completion: @escaping (Data) -> Void) { ... } } extension Worker { func fetch(objectsWithIds ids: [String], completion: @escaping ([Data]) -> Void) { var dataArr = [Data]() for i in ids.count-1 { fetch(objectWithId: ids[i]) { dataArr.append(Data) } } completion(dataArr) } }