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

Can you cast an Objective-C object using a Class object?

By Objective-C object I mean something like MyViewController, and a class object MyViewController.superclass. For example, in this function how would you cast self using targetClass? // This code doesn't compile - (void) useOtherClassImplementation…
2
votes
1 answer

How do I swizzle main bundle with test bundle

I use to swizzle main bundle with test bundle like follow in obj c #import "NSBundle+Bundle.h" #import @implementation NSBundle (Bundle) +(void)loadSwizzler { static dispatch_once_t once_token; dispatch_once(&once_token, …
Ravi Kiran
  • 219
  • 3
  • 14
2
votes
1 answer

Customizing NSLog Function on iPhone

I know that it's possible to do method swizzling for Selectors and Methods in Objective C. Is it possible to swizzle functions like NSLog to our custom function. I wanted to add some extra functionality along with NSLog in the custom…
Mahadevan Sreenivasan
  • 1,144
  • 1
  • 9
  • 26
2
votes
3 answers

Saving pointers to file in C++

I'm developing a game for a course at my school. One of the assignments is to enable saving the game to a file and later load the game from the same file. The problem I'm having are pointers. I'm not allocating anything on the stack (due to…
Nicklas Ansman
  • 121
  • 3
  • 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

NSLocale using method swizzling to change the currentLocale output for testing purposes

I'm trying to change the device currentLocale output to perform some interesting unit tests, this is the code that I'm using but it seems that the returning currentLocale doesn't get overridden. Any hint? extension NSLocale { class func…
MatterGoal
  • 16,038
  • 19
  • 109
  • 186
2
votes
0 answers

Swizzling shared framework's method outside my app

I've implemented a Swizzling category for UIViewControllers, which just NSlogs when they are presented: #import "UIViewController+Logger.h" #import @implementation UIViewController (Logger) + (void)load { static…
Elist
  • 5,313
  • 3
  • 35
  • 73
2
votes
3 answers

Replacing the content of UIImage(s) loaded from XIB at runtime

For a concept I'm developing, I need to load XIB files manually and by using class and instance method swizzling I have been able to intercept calls to imageCustomNamed, imageCustomWithContentsOfFile and imageCustomWithCGImage for the UIImage class…
user415080
  • 21
  • 2
2
votes
3 answers

Is there a way to "capture" all the UIButton taps inside an app?

I want to be able to track what buttons my users are tapping. Is there a way to "capture" or "log" all the button taps inside my app? I was thinking about method swizzling but I really rather not get into that.
YogevSitton
  • 10,068
  • 11
  • 62
  • 95
2
votes
0 answers

Can we use inout parameters in a Objective-C block?

Something like this ? ^void (__unsafe_unretained UIViewController self, UIScrollView *scrollView, CGPoint velocity, inout CGPoint *targetContentOffset){ // Something } or whats the alternative to using such paramrters. Context: I am trying to…
mohkhan
  • 11,925
  • 2
  • 24
  • 27
2
votes
1 answer

How to make the background of all UITextViews Purple without subclassing?

I have an app that I want to debug. I'd like every UITextview within the app to have a purple background. I think method swizzling is a possible solution, but I have not been able to get this to work. Question: How can I do this without…
2
votes
1 answer

Programmatically creating new instance method to track message sending

I want to design a class (TrackingClass) that would be in charge of tracking the calls to some methods of an other class (TrackedClass), i.e. of setting up the method swizzling from what I understood. So let's say I load up an array with @selectors…
Bertrand Caron
  • 2,525
  • 2
  • 22
  • 49
2
votes
1 answer

How to pass va_list between method IMPs? (objective c)

I'm trying to swizzle a function and call the original implementation with the function args. the new IMP is of the form: static id WrapperFunction(id self, SEL _cmd, ...) { va_list args; va_start(args, _cmd); originalImp(self, _cmd,…
Tomer Shiri
  • 949
  • 1
  • 10
  • 19
1
vote
2 answers

Automatic Pointer Swizzling by Java?

Suppose we have an arbitrary graph represented by nodes and pointers like this: class Node { public ValueType data; public ArrayList adj; } Now, I want to take a copy of it or write/read it on the disk (AKA serialize/deserialize). I…
Nima
  • 854
  • 3
  • 11
  • 18
1
vote
1 answer

Problems trying to apply shader to vertex array in OpenGL using C++

I have 4 dimensional vertices(X,Y,A,B) that I'd like to draw as 6 separate 2D plots (XxY, XxA, XxB, YxA, ...) My vertices are defined as follows: GLint data[MAX_N_POINT][4]; I can draw the first (X,Y) of the 2D plots just fine…
slayton
  • 20,123
  • 10
  • 60
  • 89