Skip to content

Instantly share code, notes, and snippets.

@GuilhE
Last active Jun 24, 2021
Embed
What would you like to do?
Medium article - KMM
//void example
static func createReservation() -> Future<Void, Error> {
return Future() { promise in
manager.createReservation() { data, error in
if data?.isSuccess == true {
promise(Result.success(()))
} else if let error = data?.exception {
promise(Result.failure(error.toAppError()))
}
}
}
}
//value example
static func fetchReservations() -> Future<[shared.Event], Error> {
return Future() { promise in
manager.reservations() { data, _ in
if let success = data?.data {
promise(Result.success(success as! [shared.Event]))
} else if let error = data?.exception {
promise(Result.failure(error.toAppError()))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment