#import <objc/objc.h>
#import <Foundation/Foundation.h>

@interface TestObj : NSObject
- (void)foo;
@end
 
@implementation TestObj

- (void)foo {
    [NSObject cancelPreviousPerformRequestsWithTarget:self
                                             selector:@selector(foo)
                                               object:nil];
    [self performSelector:@selector(bar) withObject:nil afterDelay:0];
     printf("foo\n");
}
 
- (void)bar
{
    printf("bar\n");
}

- (void)baz
{
   for (int i = 0; i < 3; i++)
    {
        [self foo];
    }
}

int main()
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    id obj = [[TestObj alloc] init];
    [obj baz];
    [[NSRunLoop currentRunLoop] run];

    [pool release];

    return 0;
}
@end
