关于Category的问题
我应用category语法写了一个小程序,但xcode报错.
代码如下
NSString+reverse.h
#import <Cocoa/Cocoa.h>
@interface NSString (reverse)
-(NSString*)reverse();
@end
#import "NSString+reverse.h"
@implementation NSString(reverse)
-(NSString*)reverse(){
int length=[this length];
NSMutableString* reverse=[[NSString alloc] initWithCapacity:length];
while(length>0){
[reverse appendSting:[NSString stringWithFormat:@"%c",[self characterAtIndex:--length]]];
}
return [reverse autorelease];
}
@end
#import <Foundation/Foundation.h>
#import "NSString+reverse.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* string=[[NSString alloc] init];
string=@"hello World";
NSLog(@"the reverse string is : %@",[string reverse]);
[pool drain];
return 0;
}