jrswizzle
jrswizzle copied to clipboard
Can i use swizzle a method witht a block implementation
Hi, Jonathan
Can Can i use swizzle a method witht a block implementation
Normal swizzleMetod:(SEL)slector withSelctor:(SEL)newSelector
But I want this swizzleMetod:(SEL)slector withBlock:(^ )block
because I cannot import WebView(In WebKit framework) to iOS project, but I want swizzle WebView's method, i cannot write a category for WebView, So I cannot find a place to put my newSector, so I want to use block,
Jonathan, can you give me some suggestions?
Thank You!
Sounds like you should just write your own WebView.h with just the method you want to swizzle. No need for blocks.
You I Write a WebView.h by myself, then write a category to swizzle method? I tried, but not ok my WebView.h like this,
#import <Foundation/Foundation.h>
@interface WebView : NSObject
@end
But in WebView's category still cannot find WebView When compile, my workmate suggest me to decompile the webkit code to my the WebView's method's list to rewrite the method than I want to swizzle, I think this maybe not so good, so I am trying other solutions, thank you all the same.
I too would like to be able to swizzle a method with a block for the implementation.
It nice and useful in a Unit Test (esp. Kiwi) where the closure behavior of blocks can be leveraged.
https://github.com/ebf/CTObjectiveCRuntimeAdditions provides such a method: class_replaceMethodWithBlock
so it might be possible...