Need help with SwizzleSwift?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

MarioIannotta
140 Stars 13 Forks MIT License 16 Commits 3 Opened issues

Description

Swizzle selectors with just one clean and elegant API

Services available

!
?

Need anything else?

Contributors list

# 46,730
Swift
blurvie...
sliding...
macOS
16 commits

SwizzleSwift

Who said that method swizzling needs to look ugly? SwizzleSwift is a little wrapper that lets you swizzle selectors just one clean and elegant API.

SwizzleSwift: Swizzle selectors with just one clean and elegant API

Version License Platform

Installation

Pods

pod 'SwizzleSwift'

Swift package manager

From Xcode, select File → Swift Packages → Add Package Dependency → Select your project → Search SwizzleSwift

Usage example

Swizzle() {

}

Given the following controller ```swift class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    print(#function)
}

override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) print(#function) }

}

extension UIViewController {

@objc private func myViewDidLoad() {
    print(#function)
    myViewDidLoad()
}

@objc private func myViewWillAppear(_ animated: Bool) { print(#function) myViewWillAppear(animated) }

} ```

Swizzling the methods like this ```swift extension UIViewController {

@objc static func methodSwizzling() -> Void {
    Swizzle(ViewController.self) {
        #selector(viewDidLoad)  #selector(myViewDidLoad)
        #selector(viewWillAppear(_:))  #selector(myViewWillAppear(_:))
    }
}

} ```

Will produce the following output

swift
myViewDidLoad()
viewDidLoad()
myViewWillAppear(_:)
viewWillAppear(_:)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.