UPDATE:
With some key suggestions and back and forth with George, I've come up with two different ways to achieve exactly what I want in CodeRunner and posted it on Github's gist site: Objective-C AOP gist
The code is rough because it's a new concept and I just finished at 1:30am. It definitely works though and has some niceties like auto-adding all methods that aren't initializers, getters or setters. [END UPDATE]
Several times (but certainly not very often) I've come across a situation where my code would be a bit DRYer if I could call a context-sensitive piece of code for each method in a class. Use of the Objective-C runtime is totally fine, I'd accept C or C++ solutions as well.
Instead of:
- (void)methodName1
{
self->selector = _cmd;
NSLog(@"This method is named: %@",_cmd);
//more code
}
- (void)methodName2
{
self->selector = _cmd;
NSLog(@"This method is named: %@",_cmd);
//more code
}
Have something like this, with the result being the same:
+ (void)AOPMethod
{
self->selector = _cmd;
NSLog(@"This method is named: %@",_cmd);
}
- (void)methodName1
{
//more code
}
- (void)methodName2
{
//more code
}
In a real-world application, AOPMethod would contain more code and there'd be more methods in the class.
P.S., I'm fairly obsessed with DRY. Along with clarity of prose and performance it's a key component of how I assess my code's quality over the long term. For each new way I can avoid repeating myself, the benefit is exponential because I break off as much code as possible in reusable classes that are shared across many projects.