Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Last active June 14, 2020 15:08
Show Gist options
  • Select an option

  • Save cipolleschi/399f8722c972a125669c1e1a4d7920f0 to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/399f8722c972a125669c1e1a4d7920f0 to your computer and use it in GitHub Desktop.
// Transform the presentation of a Modal VC into a promise.
// This pattern is useful when the modal has to pass some information back to the presenter
func promisifyModal() -> Promise<String> {
return Promise<String>(in: .main) { resolve, _, _ in
let vc = AnimalVC(store: self.store, connected: true, resolve: resolve)
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: true, completion: nil)
}
}
// Function that presents the modal and handle the data returned by it
func userTapModal() {
self.promisifyModal()
.then { [weak self] animal in
// This code is invoked when the modal is dismissed.
self?.localState.animal = animal
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment