/MOAspects

AOP Library for iOS

Primary LanguageObjective-CMIT LicenseMIT

MOAspects v0.1.5

MOAspects is AOP library for iOS.

How To Get Started

Podfile

pod 'MOAspects'

Interface

MOAspect.h

// 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;

How to use

Hook class method example

[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!

Hook instance method example

[MOAspects hookInstanceMethodForClass:[NSString class]
                             selector:@selector(length)
                      aspectsPosition:MOAspectsPositionBefore
                           usingBlock:^(NSString *string){
                               NSLog(@"hooked %@!", string);
                           }];

[@"abcde" length]; // -> hooked abcde!

Spec table

|32bit|64bit|Can Hook
Method Type
|Class
Hierarchy Hook
|Hook
Return Value
|Natural
Swift Method
| |:---:|:---:|:---:|:---:|:---:|:---:|:---:| | ⚪︎ | ⚪︎ | Instance / Class | Supported | Not supported | Not supported |