We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public extension UIColor { @objc func colorDescription() -> String { return "print rainbow colours" } private static let swizzleDescriptionImplementation: Void = { let instance: UIColor = UIColor.red let aClass: AnyClass! = object_getClass(instance) let originalMethod = class_getInstanceMethod(aClass, #selector(description)) let swizzleMethod = class_getInstanceMethod(aClass, #selector(colorDescription)) if let originalMethod = originalMethod, let swizzleMethod = swizzleMethod { method_exchangeImplementations(originalMethod, swizzleMethod) } }() public static func swizzleDesription() { _ = self.swizzleDescriptionImplementation } } override func viewDidLoad() { super.viewDidLoad() view.addSubview(tableView) print(UIColor.red) print(UIColor.green) UIColor.swizzleDesription() print("\nswizzled\n") print(UIColor.red) print(UIColor.red) UIColor.swizzleDesription() print("\nTrying to swizzle again\n") print(UIColor.red) print(UIColor.red) }
通过打印结果可见多次swizzleDescription操作,只会生效一次,并不会重复swizzle 详情请见Method swizzling in iOS swift
The text was updated successfully, but these errors were encountered:
No branches or pull requests
通过打印结果可见多次swizzleDescription操作,只会生效一次,并不会重复swizzle
详情请见Method swizzling in iOS swift
The text was updated successfully, but these errors were encountered: