Skip to content

Instantly share code, notes, and snippets.

@GuilhE
Last active June 24, 2021 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuilhE/829c8a3321282158d0ff6d932d617eb8 to your computer and use it in GitHub Desktop.
Save GuilhE/829c8a3321282158d0ff6d932d617eb8 to your computer and use it in GitHub Desktop.
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