Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@koenpunt
Last active July 1, 2017 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenpunt/081027e3d5147c89e801394d06ecd2bf to your computer and use it in GitHub Desktop.
Save koenpunt/081027e3d5147c89e801394d06ecd2bf to your computer and use it in GitHub Desktop.
UIRefreshControl override so that app correctly idles while UI testing Raw

UIRefreshControl+Testing

Follow up on https://gist.github.com/koenpunt/cf8130bdfc432d31136b, but since method swizzling apparently doesn't work so well with Swift 3 anymore, I've now created it as Obj-C protocol.

When using in a Swift project, add it to the bridging header:

#import "UIRefreshControl+Testing.h"

Then you'll need to add a -DTESTING compile flag to the configuration you use for testing to enable this only for test builds.

Imgur

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UIRefreshControl(Testing)
@end
#if TESTING
#import "UIRefreshControl+Testing.h"
#import <objc/runtime.h>
@implementation UIRefreshControl(Testing)
+ (void)load
{
Method original, swizzled;
original = class_getInstanceMethod(self, @selector(_setRefreshControlState:notify:));
swizzled = class_getInstanceMethod(self, @selector(kp__setRefreshControlState:notify:));
method_exchangeImplementations(original, swizzled);
}
- (void) kp__setRefreshControlState:(int)state notify: (BOOL)notify
{
printf("kp__setRefreshControlState\n");
}
@end
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment