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

Category +load timing issue

I have a class hierarchy as follows @interface PTLDatasource : NSObject ... @interface PTLFetchedDatasource : PTLDatasource ... And I want to add platform specific extensions to these classes that are defined in a protocol and implemented in a…
brianpartridge
  • 763
  • 8
  • 19
1
vote
1 answer

objc_setAssociatedObject in a category sets for all subclasses

I have a custom container view controller that manages the view hierarchy of my app. I know that every controller is some sort of child of this container controller. I thought it would be nice to have a category on UIViewController that would allow…
Evan Cordell
  • 4,108
  • 2
  • 31
  • 47
1
vote
1 answer

Overriding / Swizzling methods from an existing shared delegate

Is it possible to override ONLY CERTAIN functions from an exisiting delegate, without ourself being a delegate totally? I tried replacing the target IMP with mine, didn't work :'( More detail: +[SomeClass sharedDelegate] -[sharedDelegate…
RealHIFIDude
  • 71
  • 1
  • 2
  • 7
1
vote
1 answer

What function/syscall is used by iOS to read and write files

I want to intercept file read/write on iOS for providing transparent encryption/decryption functionality to some of my apps. I know I can swizzle the various SDK methods for reading/writing files to do this, but that entails a LOT of hard work and…
Karthik
  • 770
  • 1
  • 6
  • 12
0
votes
1 answer

Is - [UIView (MyOwnCategory) drawRect:] never called on 3.1.3?

I define my own my own drawRect method and it is called on 4.2.1 (iOS) 5.0 (iOS) and 4.3.2 (Simulator) sucesfully. But it never called on 3.1.3 (iPhone 2g). What reason could be for this? P.S. Since i start write the question i think about my 3.1.3…
Maxim Kholyavkin
  • 4,463
  • 2
  • 37
  • 82
0
votes
1 answer

does -[CALayer drawInContext:] do something?

According to documentation Default implementation does nothing. But... I throw exception from drawRect method and i see next callstack 3 EasyWakeup 0x0003a7b6 -[AlarmIntervalView drawRect:] + 71 4 UIKit …
Maxim Kholyavkin
  • 4,463
  • 2
  • 37
  • 82
0
votes
1 answer

Method Swizzle Crash: Vietnamese keyboard failing and crashing

EDIT: Prefixed the question with "Method Swizzle Crash" to help others find the bug. For each key pressed in the Vietnamese keyboard on the simulator or any device running iOS 4 or higher, the following message prints to the console and no character…
AWrightIV
  • 553
  • 7
  • 15
0
votes
3 answers

Replacing Methods by Memory Address

I was wondering if there was any way to swizzle a method by a memory address. For example: I have a pointer to a method 0xFFFFFF. I have an method in my application. I want to replace the pointer with the my method. Is there way that I could…
Jnani
  • 65
  • 5
0
votes
0 answers

How to Swizzle Date (not NSDate) in Swift for XCUITest?

I have one scenario where I need to change value of Date in swift while doing XCUITest. I mean if current date returns 2022/07/06 22:31, I just want it should use some different time while running UI test cases say 2022/07/06 24:31 Example: let date…
PJR
  • 13,052
  • 13
  • 64
  • 104
0
votes
1 answer

how to swizzle method of class with some customized method through extension

I'm playing around with swizzling. I've written this code to exchange implementation for a method of a class with extension. @objc class A: NSObject { @objc func name() { print("this is class A") } } extension A { @objc func…
0
votes
1 answer

What patterns exist for mocking a single function while testing?

I have a function generates a salted hash digest for some data. For the salt, it uses a random u32 value. It looks something like this: use rand::RngCore; use std::collections::hash_map::DefaultHasher; use std::hash::Hasher; fn hash(msg: &str) ->…
theory
  • 9,178
  • 10
  • 59
  • 129
0
votes
0 answers

How can I set another Info.plist instead of the main Info.plist file in the app main bundle(for some minor property)?

I want to download modified Info.plist file into the Documents folder in the runtime and make iOS to read some value from it.(Something like swizzling) I know it's impossible to write on the main Info.plist file in the App bundle but I want to set…
Emran
  • 79
  • 1
  • 11
0
votes
1 answer

Swizzling causing recursion

So when I tried to swizzle UIImage's init(named:) so that I could set the accessibility identifier with the image's name, it seems like, even though I am calling method_exchangeImplementation, both my swizzled method ftg_imageNamed(named name:…
ScottyBlades
  • 12,189
  • 5
  • 77
  • 85
0
votes
1 answer

NSURLConnection swizzling in iOS

I have created NSURLConnection method swizzling for sendSynchronousRequest, however its not been working below is my code. Whenever I am trying to call this from main function, its crashing. let originalRequestSyncSelector =…
Kashif Jilani
  • 1,207
  • 3
  • 22
  • 49
0
votes
2 answers

Usage of autorelease pool in objectAtindex swizzling for NSMutableArray

- (nullable id)myObjectAtIndex:(NSUInteger)index{ @autoreleasepool { id value = nil; if (index < self.count) { value = [self myObjectAtIndex:index]; } return value; } } I have no idea…
霍John
  • 21
  • 2