#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSEnumerator.h>
#import <stdio.h>
void print( NSArray *array ) {
NSEnumerator *enumerator = [array objectEnumerator];
id obj;
while ( obj = [enumerator nextObject] ) {
printf( "%s\n", [[obj description] cString] );
}
}
int main( int argc, const char *argv[] ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *arr = [[NSArray alloc] initWithObjects:
@"Me", @"Myself", @"I", nil];
NSMutableArray *mutable = [[NSMutableArray alloc] init];
// enumerate over items
printf( "----static array\n" );
print( arr );
// add stuff
[mutable addObject: @"One"];
[mutable addObject: @"Two"];
[mutable addObjectsFromArray: arr];
[mutable addObject: @"Three"];
// print em
printf( "----mutable array\n" );
print( mutable );
// sort then print
printf( "----sorted mutable array\n" );
[mutable sortUsingSelector: @selector( caseInsensitiveCompare: )];
print( mutable );
// free memory
[arr release];
[mutable release];
[pool release];
return 0;
}
эта программа скомпилирована с oscv0.1.4 в windows.
выдает ошибку, как показано ниже
Error: Parse error on line 6:
...import <stdio.h>
void print( NSArray
---------------------^
Expecting 'INTERFACE', 'IMPLEMENTATION', 'PROTOCOL', 'IMPORT', 'CLASS', 'DEFINE', 'EOF'
теперь я получил еще одну ошибку для программы, показанной ниже (это другая программа)
#import "Forwarder.h"
#import "Recipient.h"
int main(void)
{
Forwarder *forwarder = [Forwarder new];
Recipient *recipient = [Recipient new];
[forwarder setRecipient:recipient]; //Set the recipient.
[forwarder hello];
[recipient release];
[forwarder release];
return 0;
}
ошибка
Error: Parse error on line 3:
...Recipient : Object
- (id)hello;
@end#i
----------------------^
Expecting '<', '{'