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

UIView's drawRect not being called when swizzled

I am experimenting with advanced Objective-C methods. What I want to achieve is to append specific drawing code to an existing UIView. I started easily, I went on to declare my own drawRect method in a category: @interface UIView (Swizzled) -…
Legoless
  • 10,942
  • 7
  • 48
  • 68
3
votes
1 answer

Hook touchesBegan inside UIView class [Swizzling] with Delphi XE5

I am trying to catch all touch events globally. For that I know I can hook the touch event procedures inside the UIView class. I have the code that compiles. My implementation of the hook is procedure touchesBeganDetour(self: id; _cmd: SEL; touches:…
Runner
  • 6,073
  • 26
  • 38
3
votes
1 answer

iOS - EXC_BAD_ACCESS code = 1 UIWebView crashes after (method swizzling) init

I just switched my app over to ARC. The transition was a partial success thanks to the refactoring tool that Xcode provides. The one part that doesn't work is a strange error. I used method swizzling (method_exchangeImplementations) so that instead…
3
votes
6 answers

Advice on how to catch "attempt to insert nil object" from a device needed

Here is a situation: Hockeyapp and testflight every now and then complain about me "attempting to insert nil object" in mutable dictionaries/arrays. I know the right thing is to check for nil all the time, and I do when it makes sense.. Our…
dariaa
  • 6,285
  • 4
  • 42
  • 58
3
votes
1 answer

iOS static library does not work

I followed the instructions in this article to create a static library: http://developer.apple.com/library/ios/#technotes/iOSStaticLibraries/Articles/creating.html I built it for iPhone simulator target. It built successfully, then I imported into a…
raviparikh
  • 295
  • 1
  • 4
  • 11
3
votes
3 answers

Changing the font of every UILabel in a large app

Here's an interesting problem for you: We are in the process of re-skinning our entire app, which consists of over 100,000 lines of code and almost 100 XIB files. The new design requires (almost) every label in the app to use a new custom font,…
Senior
  • 2,259
  • 1
  • 20
  • 31
3
votes
5 answers

C++ templated array operator[] using ints

I'm trying to manipulate a special struct and I need some sort of a swizzle operator. For this it makes sense to have an overloaded array [] operator, but I don't want to have any branching since the particular specification of the struct allows for…
teodron
  • 1,410
  • 1
  • 20
  • 41
2
votes
2 answers

ShareKit method swizzling in Lion / Xcode 4.3.1?

I recently upgraded to Lion and Xcode 4.3.1 with the iOS 5 SDK, and the sharing library ShareKit is broken - it used method swizzling for its email handler. Apparently Apple has banned or at least attempted to phase out method swizzling. ShareKit…
Luke
  • 7,110
  • 6
  • 45
  • 74
2
votes
4 answers

Iphone: Replace functions using reflection

I have a small function which I want to rewrite, so that function is valid for every class. At the moment I have 10 of the same functions which all work same but every function is for another class. I know, that I have to do it with reflections, but…
DeFlo
  • 141
  • 1
  • 1
  • 9
2
votes
1 answer

Method swizzling not woking in Cocoa pod

I'm developing a pod which should use method swizzling at some point and I have a problem to call swizzled method when calling original one. I checked my swizzling in the simple POC (to be sure my swizzling is ok) and it works perfectly fine, but as…
zhanch
  • 145
  • 1
  • 8
2
votes
1 answer

How can I swizzle UIView.init

I’m attempting to swizzle the init methods of UIView and anything that subclasses it. Thus far my attempts only lead to crashes or simply do nothing noticeable. The outcome in trying to achieve is being able to override the value of the views border…
Brandon Stillitano
  • 1,304
  • 8
  • 27
2
votes
1 answer

Tracking All Events of ViewController and UIControls for Custom Analytics Framework iOS

I am working on an analytics SDK which will track all the user events which view is appeared or disappeared, Which button is clicked, Which UISwitch is turned ON or OFF, UITableView is scrolled or cell is tapped etc. I am using method swizzling for…
Abhishek
  • 1,654
  • 2
  • 18
  • 31
2
votes
2 answers

Swizzling initWithFrame: doesn't work for objects in a NIB

I'm swizzling initWithFrame: and dealloc on MKMapView and UIScrollView to add and remove notification listeners to monitor connection to an external device so I can hook up additional gesture recognizers for these views, like so: + (void)…
David Potter
  • 2,272
  • 2
  • 22
  • 35
2
votes
3 answers

Customized navigation bar hides buttons

Hope you can help with this one too... I wanted to customize my navigation bar by adding custom background picture. I found out perfect but a bit complicated method called:NavigationSwizzle. In previous project I worked without any serious problems,…
luigi7up
  • 5,779
  • 2
  • 48
  • 58
2
votes
1 answer

Verify method signatures before swizzling

I have been using method swizzling to swap implementations for unit testing. However, I am concerned that if the production code's method signatures change due to parameter changes, the unit tests will compile without error and testing run-time…
Jim
  • 21
  • 1