swizzling

Method Swizzling for UIView

我是研究僧i 提交于 2019-12-13 01:25:14
问题 I am following "This" guide. to capture UIView touchesBegan, but when I NSLog() touchesBegan in the UIViewController that this is for, it doesn't fire but does fire in the swizzled method. Is there a way I can have it fire in both? 回答1: When swizzling methods, you are basically telling the Objective-C runtime to change its internal mapping of a method selector (how you call it) to a method implementation (what it does when called). The key thing to realize is that these are actually not the

UIView's drawRect not being called when swizzled

末鹿安然 提交于 2019-12-12 14:17:51
问题 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) - (void)my_drawRect:(CGRect)rect; @end Then I swizzled the drawRect method of UIView in the implementation of the category: + (void)load { [self swizzleInstanceMethod:@selector(drawRect:) withMethod:@selector(my_drawRect:) inClass:[UIView class]]; } -

cannot get __NSCFURLSession class under ios 8

笑着哭i 提交于 2019-12-12 04:36:44
问题 I have code snippet like this c = NSClassFromString(@"__NSCFURLSession"); Using ios 7 simulator , I was able to get c c Class __NSCFURLSession 0x00000001113a2ce8 but under ios 8, I am getting c Class 0x0 0x0000000000000000 Does anyone have a solution for this ? 回答1: I think NSCFURLSession is not a real class, and iOS 8 has much stronger class type checking and is able to detect a real class. Try changing the line to: c = NSClassFromString(@"NSURLSession"); 回答2: Classes with leading

UIView method swizzling swift 3

僤鯓⒐⒋嵵緔 提交于 2019-12-11 02:21:55
问题 I'm trying to implement method swizzling in swift 3 basing on answer How to implement method swizzling swift 3.0? Here's my code: // MARK: - Swizzling private let swizzling: (UIView.Type) -> () = { view in let originalSelector = #selector(view.awakeFromNib) let swizzledSelector = #selector(view.swizzled_localization_awakeFromNib) let originalMethod = class_getInstanceMethod(view, originalSelector) let swizzledMethod = class_getInstanceMethod(view, swizzledSelector) method

Customizing NSLog Function on iPhone

[亡魂溺海] 提交于 2019-12-11 02:10:36
问题 I know that it's possible to do method swizzling for Selectors and Methods in Objective C. Is it possible to swizzle functions like NSLog to our custom function. I wanted to add some extra functionality along with NSLog in the custom function. EDIT: I finally ended up using another function which will call NSLog internally. #define NSLog(...) CustomLogger(__VA_ARGS__); void CustomLogger(NSString *format, ...) { va_list argumentList; va_start(argumentList, format); NSMutableString * message =

Is there any way to monkey-patch or swizzle an NSArray (or other Class Cluster)?

佐手、 提交于 2019-12-09 07:12:59
问题 Today I was working on a project in which I wanted to "alias" an alternative method for all instances of NSArray , and didn't think it would be too difficult with some good old-fashioned method swizzling. I broke out JRSwizzle and… [NSArray jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(objectAtIndex_accordingToMe:) error:nil]; To be clear, I paired this with the appropriate category on NSArray , an instance method called objectAtIndex_accordingToMe: . However, I was just

Method swizzling in swift 4 [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 06:07:49
问题 This question already has answers here : Swift 3.1 deprecates initialize(). How can I achieve the same thing? (9 answers) Closed 2 years ago . Swizzling in Swift 4 no longer works. Method 'initialize()' defines Objective-C class method 'initialize', which is not permitted by Swift This is something I have found a solution to so wanted to leave the questions and answer for others. 回答1: initialize() is no longer exposed: Method 'initialize()' defines Objective-C class method 'initialize', which

Swizzled method for NSMutableDictionary is not getting called

怎甘沉沦 提交于 2019-12-08 09:56:39
问题 I'm trying to swizzle NSMutableDictionary. What am I doing wrong here? I'm trying to override setObject:forKey: for NSMutableDictionary. #import "NSMutableDictionary+NilHandled.h" #import <objc/runtime.h> @implementation NSMutableDictionary (NilHandled) + (void)load{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; SEL originalSelector = @selector(setObject:forKey:); SEL swizzledSelector = @selector(swizzledSetObject:forKey:); Method originalMethod =

What function/syscall is used by iOS to read and write files

陌路散爱 提交于 2019-12-08 06:37:41
问题 I want to intercept file read/write on iOS for providing transparent encryption/decryption functionality to some of my apps. I know I can swizzle the various SDK methods for reading/writing files to do this, but that entails a LOT of hard work and is prone to error (I may miss swizzling some method, causing my application to crash/misbehave). If there is some common syscall/function used by all these methods, then I'd rather swizzle it and save on some hard work + make it more foolproof. Is

ShareKit method swizzling in Lion / Xcode 4.3.1?

帅比萌擦擦* 提交于 2019-12-07 18:51:27
问题 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 imports a file </usr/include/objc/objc-class.h> , which no longer exists, and defines its own method swizzling method SHKSwizzle . It uses this to alter MFMailComposeViewController 's viewDidDisappear: method as follows: SHKSwizzle(