Last active
June 14, 2020 15:08
-
-
Save cipolleschi/399f8722c972a125669c1e1a4d7920f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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