NOTE: This page was written in the pre-Objective 2.0 days, when I was working on my own set of changes to Objective-C. My project has since been abandoned in favor of solutions made available both by Objective-C 2.0 and by F-Script.
A quick foreach / nsnumber example. The code:
( objc ) ✂
NSArray *a = @( @4, @8, @3.14 );
foreach( item in a )
print "%s\n", [[item description] cString];
1 NSArray *a = @( @4, @8, @3 .14 ) ; 2 foreach ( item in a ) 3 print "%s\n", [[item description ] cString ];is processed into the objective-c equivalent:
( objc ) ✂
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSEnumerator *foreachEnumerator;
NSArray *a = [NSArray arrayWithObjects:
[NSNumber numberWithInt:4],
[NSNumber numberWithInt:8],
[NSNumber numberWithFloat:3.14] , nil];
foreachEnumerator = [a objectEnumerator];
id item;
while( item = [foreachEnumerator nextObject])
printf( "%s\n", [[item description] cString] );
[pool release];
return 0;
}
1 #import < Foundation/Foundation .h> 2 3 int main ( int argc, const char *argv[]) { 4 NSAutoreleasePool *pool = [NSAutoreleasePool new ]; 5 NSEnumerator *foreachEnumerator ; 6 NSArray *a = [NSArray arrayWithObjects: 7 [NSNumber numberWithInt: 4], 8 [NSNumber numberWithInt: 8], 9 [NSNumber numberWithFloat: 3 .14 ] , nil ]; 10 foreachEnumerator = [a objectEnumerator ]; 11 id item; 12 while ( item = [foreachEnumerator nextObject ]) 13 printf ( "%s\n", [[item description ] cString ] ) ; 14 [pool release ]; 15 return 0 ; 16 } To produce the expected output: