Swift Method Swizzling

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        UIViewController.swizzle()
        return true
    }

    // ....
}
//
//  ViewController.swift
//  swizzling
//
//  Created by 玉澤 裕貴 on 2019/07/10.
//  Copyright © 2019 minipro. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("kasamax")
    }
}
//
//  Swizzling.swift
//  swizzling
//
//  Created by 玉澤 裕貴 on 2019/07/10.
//  Copyright © 2019 minipro. All rights reserved.
//

import Foundation
import UIKit

protocol Accessible {
    func generateIdentifier()
}

extension Accessible where Self:UIViewController {
    func generateIdentifier() {
        print("generated")
    }
}

extension UIViewController: Accessible {

    @objc private func generate() {
        generateIdentifier()
    }

    private static let swizzleImpl: Void = {
        let originalMethod = class_getInstanceMethod(UIViewController.self, #selector(viewDidLoad))
        let swizzledMethod = class_getInstanceMethod(UIViewController.self, #selector(generate))
        if let originalMethod = originalMethod, let swizzledMethod = swizzledMethod {
            method_exchangeImplementations(originalMethod, swizzledMethod)
        }
    }()

    public static func swizzle() {
        _ = swizzleImpl
    }
}