MOAspects is AOP library for iOS.
pod 'MOAspects'
// hook instance method
+ (BOOL)hookInstanceMethodForClass:(Class)clazz
selector:(SEL)selector
aspectsPosition:(MOAspectsPosition)aspectsPosition
usingBlock:(id)block;
// hook class method
+ (BOOL)hookClassMethodForClass:(Class)clazz
selector:(SEL)selector
aspectsPosition:(MOAspectsPosition)aspectsPosition
usingBlock:(id)block;
[MOAspects hookClassMethodForClass:[NSNumber class]
selector:@selector(numberWithInt:)
aspectsPosition:MOAspectsPositionBefore
usingBlock:^(id class, int intVar){
NSLog(@"hooked %d number!", intVar);
}];
[NSNumber numberWithInt:10]; // -> hooked 10 number!
[MOAspects hookInstanceMethodForClass:[NSString class]
selector:@selector(length)
aspectsPosition:MOAspectsPositionBefore
usingBlock:^(NSString *string){
NSLog(@"hooked %@!", string);
}];
[@"abcde" length]; // -> hooked abcde!
|32bit|64bit|Can Hook
Method Type|Class
Hierarchy Hook|Hook
Return Value|Natural
Swift Method|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| ⚪︎ | ⚪︎ | Instance / Class | Supported | Not supported | Not supported |