A convenient base class for advice objects. More...
#import <AOCAdvice.h>
Public Member Functions | |
(id< AOCInvocationProtocol >) | - invocation |
A convenient base class for advice objects.
Advice objects needn't be a subclass of AOCAdvice, they must simply implement AOCAdviceProtocol. AOCAdvice is only provided for convenience.
The AOCAdvice class invokes "before", "instead of", and "after" methods with the same arguments as the actual method that the advice is running for. For example, if the advice is installed for the selector:
-(double)divide:(double)numerator by:(double)denominator;
AOCAdvice will run these methods on itself if they exist:
-(double)adviceBeforeDivide:(double)numerator by:(double)denominator; -(double)adviceInsteadOfDivide:(double)numerator by:(double)denominator; -(double)adviceAfterDivide:(double)numerator by:(double)denominator;
The return values of -adviceBefore[sel]
and -adviceAfter[sel]
are ignored.
In -adviceBefore[sel]
, the arguments may be modified via [[self invocation] setArgument:... atIndex:...]
before the actual method is called. Be aware that the first argument is at index 2.
If -adviceInsteadOf[sel]
is implemented, then the advice will replace the actual method. The actual method will not be called, and the return value from -adviceInsteadOf[sel] is treated as the actual return value.
In -adviceAfter[sel]
, the return value may be modified via [[self invocation] setReturnValue:...]
after the actual method has been called. You can also retreive the return value of the actual method via [[self invocation] getReturnValue:...]
.
- (id< AOCInvocationProtocol >) invocation |