Skip to content

Instantly share code, notes, and snippets.

@beyzaince
Created November 23, 2021 17:19
Show Gist options
  • Select an option

  • Save beyzaince/1670f210faca03c980b97f861719b971 to your computer and use it in GitHub Desktop.

Select an option

Save beyzaince/1670f210faca03c980b97f861719b971 to your computer and use it in GitHub Desktop.

Revisions

  1. beyzaince created this gist Nov 23, 2021.
    11 changes: 11 additions & 0 deletions SwizzleImage.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    public extension UIImageView {
    static func swizzleSetImageWithUrl() {
    guard let setImageWithMethod = class_getInstanceMethod(UIImageView.self, #selector(setImageWith(path:placeholder:completion:))),
    let swizzledMethod = class_getInstanceMethod(UIImageView.self, #selector(setStaticImage)) else { return }
    method_exchangeImplementations(setImageWithMethod, swizzledMethod)
    }

    @objc private func setStaticImage() {
    sd_setImage(with: URL(string: ""), placeholderImage: UIImage(named: "mock_snapshot_image"), completed: nil)
    }
    }