Questions tagged [swizzling]

Swizzling refers to the extraction, rearrangement, and possible duplication of elements of tuple types. On many GPUs swizzling is free or at least cheap, and smart use of swizzling can make your code more efficient. However, inappropriate use of swizzling can also make your code incredibly hard to read, and may make it hard for the compiler to optimize it.

Swizzling refers to the extraction, rearrangement, and possible duplication of elements of tuple types. On many GPUs swizzling is free or at least cheap, and smart use of swizzling can make your code more efficient. However, inappropriate use of swizzling can also make your code incredibly hard to read, and may make it hard for the compiler to optimize it.

Matrices may also be swizzled, but they require two swizzle operations in sequence. The first (leftmost) swizzle is a swizzle on rows, the second (rightmost) swizzle is a swizzle on columns. This notation permits permutation of rows and columns as well as the extraction of submatrices.

See Swizzling and Write Masking.

151 questions
0
votes
1 answer

How to get variables from block with id type

I have block declaration typedef void (^ServerResponse)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error); I have variable of type id myObj; which contains that block inside. The question is how to get access…
Vlad Polyanskiy
  • 2,589
  • 2
  • 18
  • 21
0
votes
1 answer

Swift 4 + swizzle viewWillAppear()

My question is not about how to swizzle, but rather what is happening in this particular code snippet: private let swizzling: (UIViewController.Type) -> () = { viewController in let originalSelector =…
mike.tihonchik
  • 6,855
  • 3
  • 32
  • 47
0
votes
1 answer

How to swizzle viewDidLoad method in UIViewController in swift 4? initialize() is deprecated in swift 4

I want to swizzle viewDidLoad in a UIViewController extension but initialize() method which was overridden in swift3 and was working is not supported by swift4. Can anyone give me any solution to this? My code in swift3 was as below. extension…
Soumen
  • 2,070
  • 21
  • 25
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

Method swizzling in Objective C

I am learning method swizzling in Objective-C. Below is my code to swizzle +(void)load{ NSLog(@"Load %@",[self class]); static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; …
Dinesh Selvaraj
  • 634
  • 7
  • 9
0
votes
2 answers

Xcode8+ ipad. Method Swizzling UITableView backgroundColor crash

+ (void)load { [super load]; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class aClass = [self class]; SEL selector = @selector(setBackgroundColor:); SEL _selector =…
0
votes
2 answers

AppDelegate Class not Available to Obj-C Embedded Library in iOS Swift App

I have a library written in Objective C, published as a Cocoapod. Part of what the library does is some swizzling of the AppDelegate class of any app that it is added to. When the library is added to a simple Objective-C app (a single-page app with…
Blake Clough
  • 263
  • 2
  • 10
0
votes
0 answers

generic call implementation method

I can call implementation method, if I known his parameters. as example let method: Method = class_getInstanceMethod(owner.dynamicType, selector) let implementation = method_getImplementation(method) // if i known this ((String, String) ->…
EvGeniy Ilyin
  • 1,817
  • 1
  • 21
  • 38
0
votes
1 answer

Define swizzling programmatically (as in GLSL)

How would one write swizzling as a defined behaviour in a programming language? (swizzling members like matrices and vectors in GLSL) So if I wanted to make a programming language that would allow the definition of swizzling on some members, what…
Peter Lenkefi
  • 1,306
  • 11
  • 29
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

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

Objective-C swizzled method not receiving arguments

I'm developing an app that needs to perform some swizzling. I'm swizzling a method -(void)m1:(CMAcceleration)a; with another one that I provide. -(void)newM(id self, SEL _cmd, ...){ va_list args; va_start(args, _cmd); //... NSInteger…
Leonardo Marques
  • 3,721
  • 7
  • 36
  • 50
0
votes
0 answers

Unrecognized selector sent to instance but it should

I'm crashing with unrecognized selector sent to instance xxxx but in LLDB I can confirm that the object should be responding: (lldb) po [0x7fce2b95d480 class] XXXViewController (lldb) e (BOOL)[0x7fce2b95d480…
Avba
  • 14,822
  • 20
  • 92
  • 192