fork(1) download
  1. #import <objc/objc.h>
  2. #import <Foundation/Foundation.h>
  3.  
  4. @interface TestObj : NSObject
  5. - (void)foo;
  6. @end
  7.  
  8. @implementation TestObj
  9.  
  10. - (void)foo {
  11. [NSObject cancelPreviousPerformRequestsWithTarget:self
  12. selector:@selector(foo)
  13. object:nil];
  14. [self performSelector:@selector(bar) withObject:nil afterDelay:0];
  15. printf("foo\n");
  16. }
  17.  
  18. - (void)bar
  19. {
  20. printf("bar\n");
  21. }
  22.  
  23. - (void)baz
  24. {
  25. for (int i = 0; i < 3; i++)
  26. {
  27. [self foo];
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  34.  
  35. id obj = [[TestObj alloc] init];
  36. [obj baz];
  37. [[NSRunLoop currentRunLoop] run];
  38.  
  39. [pool release];
  40.  
  41. return 0;
  42. }
  43. @end
  44.  
Success #stdin #stdout 0.02s 10472KB
stdin
Standard input is empty
stdout
foo
foo
foo
bar
bar
bar