2008-01-20 02:28:13 Basic Obj-C 2 GC Example
This compiles with "gcc -std=c99 -fobjc-gc-only -o test test.m -framework Foundation"
( objc )
  1  #import <Foundation/Foundation.h>
2
3 @interface Bug : NSObject {
4 NSString *name;
5 }
6 @property (readwrite, copy) NSString *name;
7 @end
8
9 @implementation Bug
10 @synthesize name;
11 @end
12
13 int main( int argc, const char *argv[] ) {
14 NSMutableArray *bugCollection = [NSMutableArray new];
15
16 for (int i=0; i<100; i++) {
17 Bug *bugsy = [Bug new];
18 bugsy.name = @".";
19 [bugCollection addObject:bugsy];
20 }
21
22 NSLog(@"One dot per bug in the collection:");
23 for ( Bug *thisBug in bugCollection )
24 printf( "%s", [thisBug.name cStringUsingEncoding:NSASCIIStringEncoding] );
25
26 printf( "\n" );
27 return 0;
28 }


The output, for what it's worth, looks simply like this:
  1  [487 14:50:34][jeff][~/Programming/Objective-C]% ./test
2 2008-01-20 14:50:35.722 06[8178:807] One dot per bug in the collection:
3 ……………………………………………………………………………………….
Leave a comment