# Chapter 23: Coordinator Pattern (Bug)

**URL:** <https://forums.kodeco.com/t/chapter-23-coordinator-pattern-bug/110990>\
**Category:** Design Patterns by Tutorials\
**Created:** [June 3, 2020, 4:24am UTC](https://forums.kodeco.com/t/chapter-23-coordinator-pattern-bug/110990 "2020-06-03T04:24:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![and1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/and1/32/105896_2.png) [@and1](https://forums.kodeco.com/u/and1)\
**Post date:** [June 3, 2020, 4:24am UTC](https://forums.kodeco.com/t/chapter-23-coordinator-pattern-bug/110990/1 "2020-06-03T04:24:59Z")

</div>

Hi, finally starting to understand the coordinator pattern!

There is a bug in the final app:

When you swipe down to manually dismiss the modally presented ‘VisitType’ view controller, the performOnDismissed method is never triggered. The child coordinator is never removed.

Pressing the ‘cancel’ button on the ‘VisitType’ view controller calls performOnDismissed so the child coordinator is removed.

Obviously, sometimes people just swipe down to dismiss the view controller. How do we remove the child coordinator in these cases?

Thanks!

![VisitType](https://files.chunter.kodeco.com/original/3X/f/3/f338feec1c26996d94c809fb2ea5d79dc6a4cf50.png)

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 8, 2020, 2:10am UTC](https://forums.kodeco.com/t/chapter-23-coordinator-pattern-bug/110990/2 "2020-07-08T02:10:29Z")

</div>

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![jrg.developer](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jrg.developer/32/109958_2.png) [@jrg.developer](https://forums.kodeco.com/u/jrg.developer)\
**Post date:** [July 10, 2020, 4:13am UTC](https://forums.kodeco.com/t/chapter-23-coordinator-pattern-bug/110990/3 "2020-07-10T04:13:16Z")

</div>

> [@and1](#):
>
> There is a bug in the final app:
> 
> When you swipe down to manually dismiss the modally presented ‘VisitType’ view controller, the performOnDismissed method is never triggered. The child coordinator is never removed.

You’re right –– this does appear to be an issue… 😱

As you hint at as well, iOS 13 changes the default way that view controllers are presented modally. They can now be dismissed by swiping down too. The `ModalNavigationRouter` doesn’t currently detect when this happens, so it doesn’t call `performOnDismissed` and nothing is cleaned up!

Fortunately, there’s an easy fix for this, by conforming to `UIAdaptivePresentationControllerDelegate`:

1. Make `ModalNavigationRouter` conform to `UIAdaptivePresentationControllerDelegate` by adding the following to the end of **ModalNavigationRouter.swift** :

```swift
extension ModalNavigationRouter: UIAdaptivePresentationControllerDelegate {
  public func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
    performOnDismissed(for: presentationController.presentedViewController)
  }
}

```

1. Still within `ModalNavigationRouter`, add the following right before the closing curly brace within `init(parentViewController: UIViewController)`:

```swift
navigationController.presentationController?.delegate = self

```

Check out the docs for [UIAdaptivePresentationControllerDelegate](https://developer.apple.com/documentation/uikit/uiadaptivepresentationcontrollerdelegate) for more information on what it does.

Here’s also another [useful article](https://sarunw.com/posts/modality-changes-in-ios13/) about the modal presentation changes in iOS 13.

I’ll make sure the next edition of the book includes this fix too –– Thanks for pointing it out! :]
