jrswizzle icon indicating copy to clipboard operation
jrswizzle copied to clipboard

Can i use swizzle a method witht a block implementation

Open Fykec opened this issue 12 years ago • 3 comments

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!

Fykec avatar Mar 02 '12 11:03 Fykec

Sounds like you should just write your own WebView.h with just the method you want to swizzle. No need for blocks.

rentzsch avatar Mar 02 '12 21:03 rentzsch

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.

Fykec avatar Mar 03 '12 03:03 Fykec

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...

brendanjerwin avatar May 20 '13 18:05 brendanjerwin