Questions tagged [method-swizzling]

Method swizzling is the process of changing the implementation of an existing method.

Method swizzling is the process of changing the implementation of an existing method, swapping its implementation with another's that have the same signature.

The technique is possible in languages where the method implementation is allowed to be changed at runtime. One example is Objective-C, in which is used by Apple’s Foundation Framework to implement Key-Value Observing.

108 questions
2
votes
1 answer

UIViewController method swizzling not working

I am using a category on UIViewController to swizzle the viewWillAppear: method across multiple ViewControllers. @implementation UIViewController (Tracking) +(void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ …
KrishnaKumar
  • 188
  • 10
2
votes
1 answer

iOS Method Method Swizzling - 2 SDK trying to Swizzle "ViewDidAppear" method in 1 app, then what will happen?

If I add 2 SDKs in my iOS app, which inside doing method swizzling for same method "ViewDidAppear" then what could (good + bad) be happened at runtime.
2
votes
1 answer

How to swizzle ScrollViewDidScroll or other scrollview methods for UICollectionView

I want to swizzle some scrollview methods for my collection/tableview to track some events. I am getting errors as it is not able to find scrollViewDidScroll: Method in collectionview. I tried to use below code extension UICollectionView { …
Jasveer Singh
  • 354
  • 3
  • 10
2
votes
1 answer

Change UIAlertView with swizzling

I've recently been handed a private hardware SDK to integrate into my company's mobile app. Everything works great except they are using a UIAlertView as the result of some opaque method call, and my design team wants to brand this. I don't have…
helloB
  • 3,472
  • 10
  • 40
  • 87
2
votes
1 answer

Swizzling in Swift with StaticString

I am trying to swizzle a Swift function that contains a StaticString parameter. Here is what I tried: let method = class_getClassMethod(self, original1) class ABC { public static func updateABC(context: Int, str: StaticString) { } } However,…
Oliver Hu
  • 148
  • 7
2
votes
0 answers

EXC_BAD_ACCESS when swizzle popViewControllerAnimated:

For logging navigation between controllers, I use swizzling of -popViewControllersAnimated: method. And sometimes it causes strange crash with EXC_BAD_ACCESS. What can be the reason? - (void)sw_popViewControllerAnimated:(BOOL)animated { //1. get…
alex
  • 2,121
  • 1
  • 18
  • 24
1
vote
1 answer

mach_override() function is failing in mojave OSX 10.14

I have a small project which implements function hooking in MAC using mach_override() by Jonathan 'Wolf' Rentzsch:https://github.com/rentzsch/mach_override I have hooked one of the functions of kextstat process from mac. So when I am executing…
1
vote
2 answers

Swizzling UIResponder Touch events not invoking original method implementation

I am trying to swizzle the UITouch lifecycle events by creating a UIResponder extension. Following is an excerpt depicting the implementation for touchesBegan. public extension UIResponder { private enum TouchPhase: String { case begin …
Subzero
  • 841
  • 6
  • 20
1
vote
1 answer

How to swizzle initialization method?

I have one class MyOldController with init method -(instancetype) initWithMyController: (MyController *) myController { if((self = [self init])) { _myController = myController; } return self; } I want swizzle this…
Danil
  • 63
  • 9
1
vote
1 answer

Method swizzling doesn't work in Objective-C

I want to test method swizzling in Objective-C: Add a method goodName in AViewController #import "AViewController.h" #import "UIViewController+Tracking.h" @interface AViewController () @end @implementation AViewController - (void)viewDidLoad { …
William Hu
  • 15,423
  • 11
  • 100
  • 121
1
vote
0 answers

Swizzling NSDictionary initializer in SDK

So I'm plan to create a safe init function for NSDictionary like someone else did, but as I'm a SDK developer: I want add a switch for it, the user can decide if he want open it or not; I don't want to use Category to implement it. So I create a…
Alanc Liu
  • 1,294
  • 10
  • 15
1
vote
0 answers

Method swizzling not working on simulator

I am trying to swizzle the init methods and layout subviews of UIButton by using the following code: extension UIButton { // Swizzled method @objc func xxx_init(coder aDecoder: NSCoder) { xxx_init(coder: aDecoder) } @objc func…
JackRobinson
  • 225
  • 2
  • 11
  • 24
1
vote
2 answers

How to swizzle URLSession class method dataTask in swift 3

I want to swizzle URLSession class method dataTask but not been able to get it done. I tried this swizzling in objective-c and its working fine in that now I want to implement this in swift 3 but not getting any thing. I refer this link but its…
Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
1
vote
0 answers

Objective-c runtime list all methods of a class including swizzled ones

I am interested in mostly the swizzled methods. I've tried this Is there any way to list all swizzled methods in an iOS app? but the dependency doesn't work. Is there a brute force way to just enumerate all classes and methods to compare?
Avba
  • 14,822
  • 20
  • 92
  • 192
1
vote
1 answer

What is the difference when swizzling between these 2 mechanisms

There is a slight variation between these 2 ways of swizzling. I just want clarification if there is something fundamentally different or wrong between them Assuming we are swizzling viewDidLoad on UIView First way (using…
Avba
  • 14,822
  • 20
  • 92
  • 192