Wait for user to dismiss Modal View before executing code (Swift 2.0)
<p>I'm building an app that asks users to select a location if they don't allow access to their current location using a Modal that <strong>Presents Modally</strong> as soon as the user clicks 'Deny'. This modal has information displayed as a TableView, and the modal dismisses as soon as the user selects a row. I save this selection in a variable called <code>selectedStop</code>. <strong>I want the app to pause until the user selects a location, then as soon as the user selects a location, the app continues and the setUpMap() function executes</strong>. I've tried using an infinite <code>while</code> loop in setUpMap() and using a boolean to break out of it as soon as a user selects a row, but the while loop executes before the Modal even pops up.</p>

<p><strong>ViewController.swift</strong></p>

<pre><code>class ViewController: UIViewController {
    var selectedStop: Int!

    override func viewDidLoad() {
        super.viewDidLoad()
        // If we don't have access to the user's current location, request for it
        if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse) {
            locationManager.requestWhenInUseAuthorization()
        }
    }

    func setUpMap() {
        // do stuff with var selectedStop
    }

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        switch status {
        case .Denied:
            // if user denies access, display modal
            self.performSegueWithIdentifier("NotifyModally", sender: self)
            setUpMap() // need this func to execute AFTER location is selected
            break

        case .AuthorizedWhenInUse:
            setUpMap()
            break

        default:
            break
        }
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        if (segue.identifier == "NotifyModally") {
            let destViewController:ModalViewController = segue.destinationViewController as! ModalViewController
            // send selectedStop var to ModalViewController
            destViewController.selectedStop = selectedStop
        }
    }
}
</code></pre>

<p><strong>ModalViewController.swift</strong></p>

<pre><code>class ModalViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet weak var tableView: UITableView!

    var busStops = ["Stop 1", "Stop 2", "Stop 3"]
    var selectedStop: Int!

    func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
        return busStops.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel!.text = busStops[indexPath.row]
        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        selectedStop = indexPath.row
        dismissViewControllerAnimated(true, completion: nil)
    }
}
</code></pre>