Browse Questions
- Secure Comparator is a zero-knowledge protocol that lets two parties confirm they hold the same secret without either side transmitting it, or leaking anything usable when the secrets differ.
- TaskGroup lets you run multiple async tasks in parallel and collect all their results.
- Use protoc with the Swift plugin to generate Swift files from a .proto file provided by the backend team.
- A memory leak is memory that is allocated but never freed — usually from retain cycles.
Answer:
TaskGroup lets you run multiple async tasks in parallel and collect all their results. Use it when you have a dynamic number of parallel operations.
Code Example:
func fetchAllUsers(ids: [Int]) async throws -> [User] {
try await withThrowingTaskGroup(of: User.self) { group in
for id in ids {
group.addTask {
try await fetchUser(id: id)
}
}
var users: [User] = []
for try await user in group {
users.append(user)
}
return users
}
}
// All fetches run in parallel — much faster than sequential await
let users = try await fetchAllUsers(ids: [1, 2, 3, 4, 5])
Key Points:
withTaskGroupfor non-throwing taskswithThrowingTaskGroupwhen tasks can throw- Results arrive in completion order, not the order tasks were added