Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Last active November 28, 2019 20:55
Show Gist options
  • Save rsaenzi/3377d800ce3bf4916324ef3622a73124 to your computer and use it in GitHub Desktop.
Save rsaenzi/3377d800ce3bf4916324ef3622a73124 to your computer and use it in GitHub Desktop.
To add completion handlers to push, pop and popToRoot functions
//
// UINavigationController+Root.swift
//
// Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/)
// Copyright © 2017. All rights reserved.
//
import UIKit
extension UINavigationController {
func pushViewController(_ viewController: UIViewController, animated: Bool = true, completion: @escaping () -> Void) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
pushViewController(viewController, animated: animated)
CATransaction.commit()
}
func popViewController(animated: Bool = true, completion: @escaping () -> Void) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
popViewController(animated: animated)
CATransaction.commit()
}
func popToRootViewController(animated: Bool = true, completion: @escaping () -> Void) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
popToRootViewController(animated: animated)
CATransaction.commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment