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

Swift swizzling init function

I'm trying to capture initialisation of InputStream with file URL in Swift. I've successfully implemented such capture in Objective-C for NSInputStream class. The issue is that after exchanging initialisers, swizzled method is not triggered.…
0
votes
1 answer

Swizzling, Simulator, and Remote Push Notifications - iOS 14

I'm getting strange behavior in iOS 14 with regards to remote notifications on iOS and Firebase Cloud Messaging (FCM). DEVICE First, I cannot send Test notifications to my device from the FCM console. I followed the documentation verbatim, and a few…
0
votes
1 answer

Is it possible to Swizzle NSAttributedString.init(string:attributes)?

I am trying to swizzle NSAttributedString but getting a compile error: extension NSAttribtuedString { @objc convenience init(swizzledString: String, attributes: [NSAttributedString.Key : Any?] { ..... } } Error Method cannot be marked…
Tal Zion
  • 6,308
  • 3
  • 50
  • 73
0
votes
1 answer

Xamarin method swizzling isn't working. Why not?

I have the following Xamarin.Mac code: [Register("Swizzler")] public class Swizzler : NSObject { [DllImport("/usr/lib/libobjc.dylib")] public static extern IntPtr class_getInstanceMethod(IntPtr classHandle, IntPtr Selector); …
fractor
  • 1,534
  • 2
  • 15
  • 30
0
votes
0 answers

Is it possible to generate a wrapper for each method invocation in Objective-C?

I have a project with a lot of classes. I want to log (e.g. to stderr) invocations of each selector in runtime. My main requirement is not to change the existing code, so I can't just log the function's params at the start of each call. If some…
0
votes
1 answer

How to swizzle NSError init without hitting an infinite loop

How to call the original NSError init method when swizzling? My current implementation extension NSError { @objc class func errorSwizzle() { guard let instance = class_getInstanceMethod(self,…
Tal Zion
  • 6,308
  • 3
  • 50
  • 73
0
votes
0 answers

How to find original implementation of a method when multiple method swizzling

e.g. if origin IMP is UIViewController - ViewDidLoad In my project, may like main Project + many other SDK(frameworks), if other team member swizzling the same method, like UIViewController - ViewDidLoad, and i how to make sure or how to find out…
林晖杰
  • 61
  • 10
0
votes
2 answers

Xamarin method swizzle failing on device when calling original method

The following code works in simulator but fails on device when calling _originalSetTextMethod(self, stringParam). I suspect the issue is related to this, but can't determine the appropriate syntax in C#:…
Acco
  • 94
  • 8
0
votes
1 answer

why this UIViewController method swizzling doesn't work?

I'm trying out a code example of The NSHipster Fake Book to swizzle the viewWillAppear: method of UIViewController. But It seems that it doesn't work expectedly since the xxx_viewWillAppear: method has never been invoked. I just cannot find out why.…
Neal.Marlin
  • 494
  • 5
  • 17
0
votes
1 answer

Swizzle `init` and invoke actual implementation inside, Swift 4

I want to swizzle init(frame:) of NSView but call real init(frame:) inside. Is this possible? I know, that I can achive the same with subclassing and overriding, but it will too much work to change it in all places. I don't know how to correctly…
Bohdan Savych
  • 3,310
  • 4
  • 28
  • 47
0
votes
0 answers

Trying to trick macOS software to run on High Sierra

So I have some software that has begun to stop working now that I've updated to High Sierra. There has been no new version of the software released so I can't get a new supported version. What I am wanting to do is find out whether or not the…
mylogon
  • 2,772
  • 2
  • 28
  • 42
0
votes
1 answer

Swizzle an unknown selector of a specific class at runtime

I have a class with the following method in one of my library's public headers. A user of my class will pass in the selector and class. -(void)someMethodWithSelector(SEL)aSelector ofClass:(Class)clazz At compile time, I don't know what the selector…
iOSAddicted
  • 389
  • 1
  • 17
0
votes
0 answers

Method swizzling on NSObject, does not work with UIView

Yet another method swizzling question, not asked before. I'd like to monitor all release calls in my application, thus I decided to use method swizzling, on NSObject, so that it would be possible to monitor of all classes. The actual code has been…
0
votes
1 answer

How to implement class swizzling swift?

i have one view.xib file and it's having small container(container view) which holds all the controls like button/textfield, all the events of controls is handle by parent view.xib class file. My requirement is at one place i need to add/show parent…
Sheshnath
  • 3,293
  • 1
  • 32
  • 60
0
votes
1 answer

Identifying method name inside a swizzled method

I have a number of classes and inside class there are a number of methods defined. I need to perform a specific set of operations when each of these methods getting called. I can write the set of operations in each of the methods. But i don't want…
Sreekanth
  • 71
  • 1
  • 4