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
0
votes
0 answers

Replace method implementation in Android via reflection / class loader

I am currently doing research on techniques for runtime manipulation on mobile applications. On the iOS platform I can easily do method swizzling by calling objective-c runtime library functions such as class_replaceMethod(...). Is an equivalent way…
0
votes
1 answer

Method swizzled in objective-c is effective in everywhere

I create a category to method swizzled UITextField, it's name like UITextField+MaxLength, I implement the +load method to do swizzled, but I didn't import it in prefix header or other files, just import it in SomeViewController. I think the swizzled…
0
votes
1 answer

How to add swizzling method to UIApplication using Swift?

I have a code below trying to use swizzling method to UIApplication methods. But the methods not getting called. Meanwhile, I'm trying to add this code into a framework or a private pod. extension UIApplication { public override class func…
Soheil
  • 5,054
  • 3
  • 24
  • 43
0
votes
3 answers

Swizzled method for NSMutableDictionary is not getting called

I'm trying to swizzle NSMutableDictionary. What am I doing wrong here? I'm trying to override setObject:forKey: for NSMutableDictionary. #import "NSMutableDictionary+NilHandled.h" #import @implementation NSMutableDictionary…
0
votes
2 answers

is method_setImplementation() atomic?

what will happened if method_setImplementation() is replacing dealloc method of NSObject class,and the same time in another thread, a NSObject instance is calling or is about to call dealloc method. Will the instance get the correct address of…
zuik
  • 213
  • 5
  • 11
0
votes
1 answer

Swizzling of a function - and function known at runtime only

I want to swizzle a function in objective-c. The problem is that - I know the function that needs to be swizzled only at runtime. Now different methods in the code will have different return types, input params etc. How should I write a (generic)…
prabodhprakash
  • 3,825
  • 24
  • 48
0
votes
1 answer

Undefined symbols for architecture x86_64 when building for Simulator

I am using the imp_implementationForwardingToSelector lib for IMP forwarding to a different selector. It works fine on real devices but giving error when I am trying to build for simulators Error: Undefined symbols for architecture x86_64 SEL…
user1169079
  • 3,053
  • 5
  • 42
  • 71
0
votes
2 answers

How to swizzle NSURLSession class method dataTaskWithUrl

I have been trying to swizzle NSURLSession class method dataTaskWithRequest but not been able to get it done extension NSURLSession{ public override class func initialize() { struct Static { static var token: dispatch_once_t = 0 } …
Manu Gupta
  • 1,759
  • 1
  • 14
  • 22
0
votes
2 answers

How to swizzle init method of NSURLConnection class

I want to swizzle init init method of NSURLConnection class and i have tried this code but it doesn't seem to work for me extension NSURLConnection{ public override class func initialize() { struct Static { static var token:…
Manu Gupta
  • 1,759
  • 1
  • 14
  • 22
0
votes
1 answer

How to swizzle methods with identical names (NSNotificationCenter postNotificationName)?

I am fairly new to method swizzling, and I'd like to use it to troubleshoot a problem I am having that is likely the result of an errant call to NSNotificationCenter. To do this I want to swizzle to log out each call to NSNotificationCenter's…
helloB
  • 3,472
  • 10
  • 40
  • 87
0
votes
0 answers

Method Swizzling doesn't work for category of UIViewController

I use the normal swizzle method: void swizzleMethod(Class class, SEL originalSelector, SEL swizzledSelector) { Method originalMethod = class_getInstanceMethod(class, originalSelector); Method swizzledMethod = class_getInstanceMethod(class,…
KChen
  • 1,922
  • 14
  • 15
0
votes
3 answers

Method Swizzling to keep a cleaner Class implementation

I'm in the situation where one of the viewControllers of my app is getting pretty big, specially since I've added a "Tutorial state" which adds a different implementation for many methods of this class that I control by checking …
Andrespch
  • 370
  • 3
  • 16
0
votes
2 answers

Method Swizzling - Please explain property mapping within this implementation

I was looking into an open source pull-to-refresh control and it swizzle lifecycle methods on a UIViewController category like so: - (void)INBPullToRefreshView_viewWillAppear:(BOOL)animated { [self setClearNavigationBar:YES]; [self…
OdieO
  • 6,836
  • 7
  • 56
  • 88
0
votes
1 answer

How to replace pickerView:numberOfRowsInComponent method for 1 instance of pickerView

I want to create a pickerView programmatically and have it use it's own version of a method like pickerView:numberOfRowsInComponent. I create the instance at runtime like this: UIPickerView *myPickerView = [[UIPickerView alloc]…
KarlJay
  • 79
  • 1
  • 9
0
votes
0 answers

Swizzling new function for unit test

Short explanation: An object in NSDictionary seems to be over-released. Swizzling of an object's new function is involved and believed to be causing the problem. Long explanation: I am developing some unit-tests for code which has not been…
Yaser
  • 408
  • 2
  • 6