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
1
vote
1 answer

Port method swizzle of NSLocale.currentLocale from swift 2.3 to swift 3

Swift 3 introduced a lot of changes in the NSLocale(now Locale) class. I need to perform method swizzle of NSLocale.currentLocale() to perform Unit test of some helpers. With Swift 2.3 I could use this method: extension NSLocale { @nonobjc…
MatterGoal
  • 16,038
  • 19
  • 109
  • 186
1
vote
0 answers

Method Swizzling - Routing every method call through a custom logger without the need to change the underlying method

I am trying to write a framework that would print certain log statements including class name and method name while that method is called on an object of that class. I want to do this without the need to modify the actual method. For instance, say…
Abhinav
  • 37,684
  • 43
  • 191
  • 309
1
vote
1 answer

How to properly swizzle UIScrollView with 3D touch peek pop?

I'm trying to swizzle the UIScrollView that 3D Touch's peek and pop preview is embedded in. (I know it's a UIScrollView through the Reveal app.) I want to know whenever the user moves their finger on this scroll view/on the 3D touch preview. I tried…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
1 answer

Is Method swizzling in a static library possible?

I'm trying to create an automatic UI logging and I found method swizzling as a really nice solution to the problem. I've tried to swizzle the sendAction method of the UIApplication implementation. My issue is that sometimes it works and sometimes it…
Scianid
  • 143
  • 9
1
vote
2 answers

Change appdelegate methods from SDK

Hi all. I'm trying to develop an SDK that will register on events when the app is going to the background [like background fetch Or significant location change]. for that reason I need to write code in the appDelegate methods -…
Idan Magled
  • 2,186
  • 1
  • 23
  • 33
1
vote
1 answer

Objective C - What is the difference between IMP and function pointer?

I recently started a project where I require to do swizzling. After going through many tutorials I got a question, What is the difference between Implementation and function pointer?
bikram990
  • 1,085
  • 1
  • 14
  • 36
1
vote
1 answer

How to correctly swizzle with method_setImplementation()?

I am trying to understand how to correctly swizzle using the method_setImplementation(). So far online I have seen two predominantly popular ways to method swizzle, once is using method_setImplementation() while the other levarages…
AyBayBay
  • 1,726
  • 4
  • 18
  • 37
1
vote
0 answers

Does Android have something like iOS method swizzling (for PhoneGap plugin initialization)?

I am writing some PhoneGap plugins for both iOS and Android that wrap third-party native SDKs. In the case of iOS, I was able to use swizzling to add behavior to the AppDelegate for the purpose of initializing these libraries. Now I need to do the…
Dan
  • 641
  • 9
  • 25
1
vote
2 answers

UINavigationControllerDelegate method call crash when WYPopover used in project

I'm working on an app that incorporates WYPopoverController and it works great in place where it should. I want to add custom animations between two controllers, instead of built in push / pop. In navigation controller containing FROM and TO…
Marcin Zbijowski
  • 820
  • 1
  • 8
  • 23
1
vote
2 answers

How to swizzle into completion block of an Objective-C method?

Let's take this method as an example: + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion It's simple enough to swizzle in a…
Michael Teper
  • 4,591
  • 2
  • 32
  • 49
1
vote
1 answer

UICollectionViewCell method swizzling

i have an unexpected behavior while swizzling a method on a UITableViewCell category my .m file : #import "UICollectionViewCell+CostraintFix.h" #import @implementation UICollectionViewCell (CostraintFix) +(void)load { Method…
Giuseppe Lanza
  • 3,519
  • 1
  • 18
  • 40
1
vote
0 answers

Objective-C class identifiers are prefixed with objc_class_ instead of _OBJC_CLASS_$_

I'm trying to swizzle some methods in an application made with Objective-C. I'm getting this error: Symbol not found: _OBJC_CLASS_$_IASAvatarViewController After opening the executable in Hopper, I see that all of the classes are prefixed with…
1
vote
4 answers

Objective-C Method Swizzling example not working

I wanted to try the Method Swizzling to understand clearly how it works. Looking at this code: http://nshipster.com/method-swizzling/. I've created a class and a category, here is the code #import @interface CustomClass :…
AR89
  • 3,548
  • 7
  • 31
  • 46
0
votes
0 answers

Getting error while implementing method swizzling in Swift

I have gone through so many article and have a good idea how we should implement method swizzling. But I'm getting this error while writing the original #selector for UserDefault class. extension UserDefaults { @objc func customSetForKey(value:…
0
votes
1 answer

UIColor initWithCoder extract color name

I'm experimenting with adding a form of theming support to iOS by swizzling UIColor constructor methods. I'm having trouble with a scenario coming from a storyboard when a control uses a "named color" (the ones added to the asset catalog manually).…
Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56