开发者

parse error on objective c

#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;
}

this program compiled with oscv0.1.4 in windows. it gives an error as shown below

Error: Parse error on line 6:
...import <stdio.h>

void print( NSArray 
---------------------^
Expecting 'INTERFACE', 'IMPLEMENTATION', 'PROTOCOL', 'IMPORT', 'CLASS', 'DEFINE', 'EOF'

now i got one more error for the program shown below(it is another program)

#import "Forwarder.h"
#import "Reci开发者_StackOverflow社区pient.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 is

Error: Parse error on line 3:
...Recipient : Object
- (id)hello;
@end#i
----------------------^
Expecting '<', '{'


the format of your program must like the code shown below here main must contain Main class compare this with the link http://code.google.com/p/oscompiler/downloads/list

@interface Main : NSObject { }
@end

@implementation Main
+(void)main {
NSLog(@"Hello world!");
}
@end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜