Help for dynamicReplacement

I have some questions when use dynamicReplacement.

1.Why we need dynamicReplacement?

class ViewController: UIViewController {
}

extension UIViewController {
    @_dynamicReplacement(for: viewDidLoad())
    func _viewDidLoad() {
        print("view didLoad")
        viewDidLoad()
    }
}

Nothing happens.

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

extension ViewController {
    @_dynamicReplacement(for: viewDidLoad())
    func _viewDidLoad() {
        print("view didLoad")
        viewDidLoad()
    }
}

This will print "view didLoad".
So why not just

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        print("view didLoad")
    }
}
class ViewController: UIViewController {
}

extension ViewController {
    @_dynamicReplacement(for: viewDidLoad())
    func _viewDidLoad() {
        print("view didLoad")
        viewDidLoad()
    }
}

It will print "view didLoad" endless, why?

Terms of Service

Privacy Policy

Cookie Policy