Skip to content
AOP Library for iOS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
MOAspects
MOAspectsDemo
MOAspectsDemoSwift
MOAspectsTest Changed hook processing of MOAspects. Jul 4, 2015
.gitignore
.travis.yml
LICENSE.txt
MOAspects.podspec
Makefile
README.md

README.md

MOAspects

Build Status

MOAspects is AOP library for iOS.

Version

1.0.0

Stable version for Objective-C language.

2.1.1

Swift language supported and development version.

How To Get Started

Podfile

Stable version

pod 'MOAspects', '~> 1.0.0'

Development version

pod 'MOAspects'

Interface

MOAspect.h

#pragma mark - Hook instance method

+ (BOOL)hookInstanceMethodForClass:(Class)clazz
                          selector:(SEL)selector
                   aspectsPosition:(MOAspectsPosition)aspectsPosition
                        usingBlock:(id)block;

+ (BOOL)hookInstanceMethodForClass:(Class)clazz
                          selector:(SEL)selector
                   aspectsPosition:(MOAspectsPosition)aspectsPosition
                         hookRange:(MOAspectsHookRange)hookRange
                        usingBlock:(id)block;

#pragma mark - Hook class method

+ (BOOL)hookClassMethodForClass:(Class)clazz
                       selector:(SEL)selector
                aspectsPosition:(MOAspectsPosition)aspectsPosition
                     usingBlock:(id)block;

+ (BOOL)hookClassMethodForClass:(Class)clazz
                       selector:(SEL)selector
                aspectsPosition:(MOAspectsPosition)aspectsPosition
                      hookRange:(MOAspectsHookRange)hookRange
                     usingBlock:(id)block;

How to use

Objective-C

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!

Swift

Hook class method example

MOAspects.hookClassMethodForClass(UIScreen.self, selector:"mainScreen", position:.Before) {
    NSLog("hooked screen!")
}

UIScreen.mainScreen() // -> hooked screen!

Hook instance method example

MOAspects.hookInstanceMethodForClass(ViewController.self, selector:"viewDidLoad", position:.After) {
    NSLog("view did loaded!")
}

// -> view did loaded!

Spec table

32bit 64bit Can Hook
Method Type
Class
Hierarchy Hook
Hook
Return Value
Natural
Swift Method
Instance / Class Supported Not supported Not supported
You can’t perform that action at this time.