Swizzler 0.1.0

Swizzler 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Mar 2015

Maintained by Sash Zats.



Swizzler 0.1.0

Usage

Vanill

SEL setObjectSelector = @selector(setObject:atIndex:);
[NSArray wml_replaceInstanceMethod:setObjectSelector withBlock:^(NSArray *self, id object, NSInteger index){
    // your logic...
}];

Or if you want to call the original method from your new implementation:

__block IMP originalIMP = [NSArray wml_replaceInstanceMethod:setObjectSelector withBlock:^(NSArray *self, id object, NSInteger index){
    // hopefully this not what you're doing
    originalIMP(self, setObjectSelector, object, self.count - index - 1);
}];

Restore the original implementation, once you're done with swizzling:

[WMLSwizzler replaceClassMethod:setObjectSelector inClass:[NSArray class] withImplementation:originalIMP];

Why

TL;DR

If you're swizzling "the old" way, you might run into issues since you new selector xyz_swizzledMethod might be passed when you call the original implementation. Besides, the block-based API is nicer and more concise.

Details

Swizzling is all fun and giggles until you screw it up. Please refer to these articles for more info:

Installation

Swizzler is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Swizzler"

Author

Sash Zats, [email protected]

License

Swizzler is available under the MIT license. See the LICENSE file for more info.