0

I'm trying to test in the Playground test if my view controllers are deallocated. In my app I want to have an external controller that presents the navigation controller that has another view controller as the child, and my dismissal code is directly in the child, which should propogate up to the navigation controller and then the sideMenu controller. But neither controllers turn nil. Besides the instantiaion, I don't have any other references of the controllers, to my knowledge. What am I missing?

import UIKit
import PlaygroundSupport

class ViewController: UIViewController {

    var num = 0

    override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
        print("dismissing")
        super.dismiss(animated: flag, completion: completion)
    }

    deinit {
        print("deinit view controller")
    }

    func logout1() {
        dismiss(animated: false, completion: { print("logout1 ") })
    }
    // this doesn't work either
    func logout2() {
        navigationController?.dismiss(animated: false, completion: { print("logout2 ") })
    }
}

var vc: ViewController? = ViewController()
var navController: UINavigationController? = UINavigationController(rootViewController: vc!)
let sideMenu = UIViewController()

sideMenu.present(navController!, animated: false, completion: nil)
vc?.logout2()
print(vc) // not nil
print(navController) // not nil
Huy-Anh Hoang
  • 777
  • 6
  • 24
  • Playgrounds aren't a good place to test for memory deallocations because they hang onto the objects themselves. – vacawama Apr 24 '19 at 21:15
  • Where is a good place to quickly test these things? I'm trying to write unit tests for my presenting and dismissal. – Huy-Anh Hoang Apr 24 '19 at 22:16

0 Answers0