fork download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3.  
  4. static int count;
  5.  
  6. @interface foo: Object
  7. +(int) initCount;
  8. +(void) initialize;
  9. @end
  10.  
  11.  
  12. @implementation foo
  13. -(id) init {
  14. self = [super init];
  15. count++;
  16. return self;
  17. }
  18.  
  19. +(int) initCount {
  20. return count;
  21. }
  22.  
  23. +(void) initialize {
  24. count = 0;
  25. }
  26.  
  27. int main( int argc, const char *argv[] ) {
  28. foo *c1 = [[foo alloc] init];
  29. foo *c2 = [[foo alloc] init];
  30.  
  31. // print count
  32. printf( "foo count: %i\n", [foo initCount] );
  33.  
  34. foo *c3 = [[foo alloc] init];
  35.  
  36. // print count again
  37. printf( "foo count: %i\n", [foo initCount] );
  38.  
  39. return 0;
  40. }
  41. @end
Success #stdin #stdout 0s 2116KB
stdin
Standard input is empty
stdout
foo count: 2
foo count: 3