Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remirobert/rroloadswizzle
Method swizzling, change the implementation of an existing selector.
https://github.com/remirobert/rroloadswizzle
objective-c swizzle unittest
Last synced: about 2 months ago
JSON representation
Method swizzling, change the implementation of an existing selector.
- Host: GitHub
- URL: https://github.com/remirobert/rroloadswizzle
- Owner: remirobert
- License: mit
- Created: 2019-04-19T10:16:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-20T08:46:24.000Z (over 5 years ago)
- Last Synced: 2024-10-11T21:05:46.748Z (3 months ago)
- Topics: objective-c, swizzle, unittest
- Language: Objective-C
- Homepage:
- Size: 39.1 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RROLoadSwizzle
![buid status](https://app.bitrise.io/app/14d90a9dfd5ce2e8/status.svg?token=uQY671hjdyKtODwsl18vfA) [![codecov](https://codecov.io/gh/remirobert/RROLoadSwizzle/branch/master/graph/badge.svg)](https://codecov.io/gh/remirobert/RROLoadSwizzle)
Used to assist in unit testing.
Check **Tests** for usage.```Objective-c
//A function which is the implementation of original method.
//The function must take at least two arguments—self and _cmd.
void (*gOriginalViewDidLoad)(id, SEL);- (void)tearDown {
RRO_REVERT_SWIZZLE_ALL_METHOD([UIViewController class]);
}- (void)testThatViewDidLoadIsCalledWhenShowWindow {
__block BOOL isViewDidLoadCalled = NO;
void (^viewDidLoadBlock)(UIViewController *, SEL) = ^void (UIViewController *nav, SEL _cmd) {
isViewDidLoadCalled = true;
NSLog(@"viewDidLoad called here");//call original @selector(viewDidLoad) if needed
gOriginalViewDidLoad(nav, _cmd);
};
RRO_SWIZZLE_BLOCK([UIViewController class], @selector(viewDidLoad), viewDidLoadBlock, &gOriginalViewDidLoad);
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.rootViewController = [[UIViewController alloc] init];
[window makeKeyAndVisible];
XCTAssertTrue(isViewDidLoadCalled);
}
```