This problem came up when I was trying to pass updatedInfo from a parent UIViewController to an embedded/child UIViewController using `self.children[0].currentInfo = updatedInfo`. As it turned out, inside an "ordinary" function in the parent view controller, this worked fine. But from inside a delegate function in the parent view controller, it crashed the program. Apparently, sometimes – but not always – `self.children.isEmpty = true` inside delegate functions.

Without knowing the reason for this, I don't know how I could reliably use `self.children` to pass information. But I don't want to just avoid using it because I don't understand it. Any insights would be appreciated.

Since my app introduced too many complicating factors, I decided to examine the problem by creating a very simple "toy" app. Here's what I have (the code is below the screenshot of the storyboard):

[![enter image description here](https://i.stack.imgur.com/xR2i0.png)](https://i.stack.imgur.com/xR2i0.png)

In the MainViewController file, there's

```
import UIKit

class MainViewController: UIViewController, InfoDelegate {

    var text = "Text from MainViewController"

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.lightGray
        printString("Text from MainViewController's viewDidLoad")
    }

    // Ordinary func
    func printString(_ string: String) {
        print(string)
        print("In printString, self.children.isEmpty is \(self.children.isEmpty)")
    }

    // Delegate func
    func messageString(_ string: String) {
        print(string)
        print("In messageString, self.children.isEmpty is \(self.children.isEmpty)")
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        if let textViewController = segue.destination as? TextViewController {
            textViewController.text = text
            textViewController.delegate = self
        }
    }
}

```

And in TextViewController, there's

```
import UIKit

protocol InfoDelegate: AnyObject { func messageString(_ string: String) }

class TextViewController: UIViewController {

    @IBOutlet weak var textView: UITextView!
    var text = "Text from TextViewController"
    weak var delegate: InfoDelegate?

    override func viewDidLoad() {
        super.viewDidLoad()
        textView.text = text
        delegate?.messageString("Text from TextViewController's InfoDelegate")
    }
}

```