Skip to content

Wondermall/Swizzler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swizzler

Build Status Version License Platform Twitter: @zats

Usage

Vanilla swizzling:

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, sash@zats.io

License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors